1.axios(vue中的ajax)
下载:npm install axios
安装:npm install http-server -g
http-server
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
<router-link to="/home">首页</router-link>
<router-link to="/detal">详情页</router-link>
<router-view></router-view>
</div>
<script src="js/vue.js"></script>
<script src="js/vue-router.js"></script>
<script src="js/axios.js"></script>
<script>
var Home={
template:`
<h1>这是首页</h1>
`
}
var Detal={
template:`
<div>
<h1>这是详情页</h1>
<table>
<thead>
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>数量</td>
<td>小计</td>
</tr>
</thead>
<tbody>
<tr v-for="value in list">
<td>{{value.num}}</td>
<td>{{value.name}}</td>
<td>{{value.price}}</td>
<td>{{value.count}}</td>
<td>{{value.sum}}</td>
</tr>
</tbody>
</table>
</div>
`,
data:function(){
return{
list:null
}
},
mounted:function(){
var self=this;
axios({
method:"get",
url:"list.json"
}).then(function(resp){
console.log(resp.data)
self.list=resp.data
}).catch(function(err){
})
}
}
const routes=[
{path:"/",component:Home},
{path:"/home",component:Home},
{path:"/detal",component:Detal}
]
const router=new VueRouter({
routes:routes
})
new Vue({
el:"#app",
router:router
})
</script>
</body>
</html>