vue中的axios

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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容