_axios 模拟ajax">
赞
踩
用于更加简洁地发送ajax请求
模拟后台返回的数据
{
"success":true,
"code":100,
"messsage":"成功",
"data":[
{"name":"诺亚","des":"第一道光"},
{"name":"雷杰多","des":"宇宙中的传说"},
{"name":"撒加","des":"传说级奥特曼"}
]
}
axios发送ajax请求,并渲染数据
<div id="app"> <table border="1"> <tr v-for="user in users"> <td>{{user.name}}</td> <td>{{user.des}}</td> </tr> </table> </div> <script> var vm = new Vue({ el:"#app", data:{ users:[] }, created(){ this.getUserList(); }, methods:{ getUserList(){ axios.get("json/data.json") .then(response => { //请求成功执行then console.log(response); this.users = response.data.data; }) .catch(error =>{ //请求失败执行catch console.log(error); }) } } }); </script>
效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。