1.导入脚手架axios.min.js和vue.min.js
2.模拟请求数据data.json
{
"sucess": true,
"code": 20000,
"message": "成功",
"data": {
"items": [
{"name": "lucy", "age": 20},
{"name": "mary", "age": 21},
{"name": "jack", "age": 23}
]
}
}
3.test.html界面模拟
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<div v-for="user in userList">
{{user.name}} -- {{user.age}}
</div>
</div>
<script src="vue.min.js"></script>
<script src="vue-router.min.js"></script>
<script src="axios.min.js"></script>
<script>
new Vue({
el: '#app',
data: {
userList:[]
},
created() {
this.getUserList();
},
mouted() {
},
methods: {
getUserList() {
axios.get("data.json")
.then(response => {
this.userList = response.data.data.items
console.log(this.userList);
})
.catch(error => {
})
}
}
})
</script>
</body>
</html>
4.测试结果