作者: 4e25978dbeb8 | 来源:发表于2018-09-25 19:42 被阅读0次

    axios

    <div id="app">
        <!--1-->
        <router-link to="/home">首页</router-link>
        <router-link to="/detail">详情页</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>
        //2
        var Home = {
            template:`
            <div>
                <h1>This is home</h1>
            </div>
            `
        };
        var Detail = {
            template:`
            <div>
                <h1>这是详情页内容</h1>
                <table border=1 cellspacing=0>
                    <thead>
                        <tr>
                            <td>编号</td>
                            <td>品名</td>
                            <td>单价</td>
                            <td>数量</td>
                            <td>小计</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="value in fruitlist">
                            <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{
                    fruitlist:null
                }
            },
            mounted:function(){
                var god = this;
                axios({
                    method:"get",//发送数据的方式
                    url:"list.json"
                }).then(function(resp){//请求成功
                    console.log(resp.data);
                    god.fruitlist = resp.data
                }).catch(function(err){
    
                });
            }
        };
        //3
        const routes=[
            {path:"/",component:Home},
            {path:"/home",component:Home},
            {path:"/detail",component:Detail}
        ];
        //4
        const router= new VueRouter({
            routes:routes
        });
        //5
        new Vue({
            el:"#app",
            router:router
        });
    </script>
    

    <style>
    a{
    text-decoration: none;
    }
    .router-link-active{
    color: #ff1db5;
    }
    .adsd{

    }
    

    </style>
    <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>
    var Home ={
    template:<h1>这是首页</h1>
    };
    var User ={
    template:<div> <h1>这是用户页</h1> <ul> <li> <router-link to="/user/regist?uname=jack&age=18">注册</router-link> </li> <li> <router-link to="/user/login/alice/20">登录</router-link> </li> </ul> <router-view></router-view> </div>
    };
    var Regist = {
    template:<div> <h2>这是注册页</h2> <a href="">{{$route.query}}</a> <ul> <li>{{$route.query.uname}}</li> <li>{{$route.query.age}}</li> </ul> </div>
    };
    var Login = {
    template:<div> <h2>这是登录页</h2> <p>{{$route.params}}</p> <ul> <li>{{$route.params.username}}</li> <li>{{$route.params.userage}}</li> </ul> </div>
    };
    const routes=[

        {path:"/",component:Home},
        {path:"/home",component:Home},
        {path:"/user",component:User,
            children:[
                {path:"/user/regist",component:Regist},
                {path:"/user/login/:username/:userage",component:Login}
            ]
        }
    ];
    const route=new VueRouter({
        routes:routes,
        linkActiveClass:"adsd"
    });
    new Vue({
        el:"#app",
        router:route
    });
    

    </script>
    </body>

    相关文章

      网友评论

          本文标题:

          本文链接:https://www.haomeiwen.com/subject/ohzloftx.html