Axios

1.用于前端页面和后台数据的交互
2.下载

npm install axios

安装

npm install http-server -g

开启服务器:http-server
3.实例

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div id="app">
            <router-link to="home">首页</router-link>
            <router-link to="user">用户页</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 User={
                template:`
                <div>
                  <h1>用户页</h1>
                  <table border=1 cellspacing=0>
                     <thead>
                       <tr>
                         <th>编号</th>
                         <th>品名</th>
                         <th>单价</th>
                         <th>数量</th>
                         <th>小计</th>
                       </tr>
                     </thead>
                     <tbody>
                       <tr v-for="value in list">
                         <td>{{value.num}}</td>
                         <td>{{value.pname}}</td>
                         <td>{{value.price}}</td>
                         <td>{{value.count}}</td>
                         <td>{{value.sub}}</td>
                       </tr>
                     </tbody>
                  </table>
                </div>
                `,
                data:function(){
                    return{
                        list:null
                    }
                },
                mounted:function(){
                    var self=this;
                    axios({
                        method:"get",
                        url:"1.json"
                    }).then(function(resp){
                        console.log(resp.data);
                    }).catch(function(err){
                        console.log(err)
                    })
                }
            }
            const routes=[
              {path:"/",component:Home},
              {path:"/home",component:Home},
              {path:"/user",component:User}
            ]
            const router=new VueRouter({
                routes:routes
            })
            new Vue({
                el:"#app",
                router:router
            })
        </script>
    </body>
</html>

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

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,876评论 25 709
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,033评论 3 119
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,175评论 1 32
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 13,150评论 2 59
  • 他在田野里弹吉他的那一幕,在我的脑海里就像一幅画,被钉在墙上,无法取下。 ——mv《四月物语》
    清酒安阅读 106评论 0 1