vue的axios的应用

<!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>
<!-- 1.在html页面中引入axios的js文件,包含vue的js文件 
    2.编写具体实现代码
-->
<body>
    <div id="app">
        <table>
            <tr v-for="user in userList">
                <td>{{user.name}}</td>
                <td>{{user.age}}</td>
            </tr>
        </table>
    </div>
    <script src="vue.min.js"></script>
    <script src="axios.min.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                userList:[]
            },
            created(){//在页面渲染之前执行
                // 调用方法,得到返回json数据
                this.getList()
            },
            methods:{
                getList(){
                    // 使用axios方式ajax请求
                    //   axios.get("请求的接口路径")
                    axios.get("user.json")  
                    .then(response=>{//请求成功
                            //console.log(response)
                         this.userList = response.data.data.item
                         console.log(this.userList)
                    })
                   
                    .cacth(error=>{//请求失败
                        //console.log(error)
                    })
                }
            }
        })
    </script>
</body>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值