路由

傳參

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-link to='/one'>首頁</router-link>
        <router-link to='/two'>用戶頁</router-link>
        <router-view></router-view>
    </div>
    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
    <script>
        var One={
            template:`
                <h1>這是首頁</h1>
            `
        }
        var Two={
            template:`
                <div>
                    <h2>這是用戶頁</h2>
                    <ul>
                        <li>
                            <router-link to='/two/a?uname=jack&upwd=123'>注冊(cè)</router-link>
                        </li>
                        <li>
                            <router-link to='/two/b/rose/456'>登錄</router-link>
                        </li>
                    </ul>
                    <router-view></router-view>
                </div>
            `
        }
        
        var A={
            template:`
                <div>
                    <h3>這是h3</h3>
                    <a href=''>{{$route.query}}</a>
                    <a href=''>uname:{{$route.query.uname}}</a>
                    <a href=''>upwd:{{$route.query.upwd}}</a>
                </div>
            `
        }
        
        var B={
            template:`
                <div>
                    <i>我是傾斜的</i>
                    <a>{{$route.params}}</a>
                    <a>uname:{{$route.params.uname}}</a>
                    <a>upwd:{{$route.params.upwd}}</a>
                </div>
            `
        }
        
        const routes=[
            {path:'/',component:One},
            {path:'/one',component:One},
            {
                path:'/two',
                component:Two,
                children:[
                    {path:'a',component:A},
                    {path:'b/:uname/:upwd',component:B}
                ]
            }
        ]
        
        const router=new VueRouter({
            routes:routes
        })
        
        new Vue({
            el:'#app',
            router:router
        })
    </script>
</body>
</html>

axios

下載:npm install axios
版本
1.0:vue-resource
2.0:axios(相當(dāng)于庫)
Vue中的ajax
ajax作用:前端頁面和后臺(tái)數(shù)據(jù)做交互
在寫是需要有一個(gè).json的文檔

axios({
  method:'get'//get post,
  url:'路徑'
}).then(function(rext){//請(qǐng)求成功
  console.log(rext.data)
}).catch(function(tex){//請(qǐng)求失敗
  console.log(tex)
})

在執(zhí)行時(shí),需要安裝http-server
安裝指令:npm install http-server -g
開啟一個(gè)服務(wù):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='index'>用戶頁</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 Index={
            template:`
                <div>
                    <h1>這是用戶頁</h1>
                    <table border=1 cellspacing=0>
                        <thead>
                            <tr>
                                <th>編號(hào)</th>
                                <th>品名</th>
                                <th>單價(jià)</th>
                                <th>數(shù)量</th>
                                <th>小計(jì)</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 c=this;
                axios({
                    method:'get',
                    url:'fru.json'
                }).then(function(a){
                    console.log(a.data)
                    c.list=a.data;
                }).catch(function(b){
                    console.log(b)
                })
            }
        }
        
        const routes=[
            {path:'/',component:Home},
            {path:'/home',component:Home},
            {path:'/index',component:Index}
        ]
        
        const router=new VueRouter({
            routes:routes
        })
        
        new Vue({
            el:'#app',
            router:router
        })
    </script>
</body>
</html>
[
    {
        "num":1,
        "pname":"apple",
        "price":2,
        "count":3,
        "sub":6
    },
    {
        "num":1,
        "pname":"apple",
        "price":2,
        "count":3,
        "sub":6
    },
    {
        "num":1,
        "pname":"apple",
        "price":2,
        "count":3,
        "sub":6
    }
]
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 路由:vue-router 帶三方工具庫 創(chuàng)建單頁面應(yīng)用 spa (single page applicatio...
    雨笑_e29c閱讀 836評(píng)論 0 0
  • 路由:vue-router 帶三方工具庫創(chuàng)建單頁面應(yīng)用 spa (single page applicatio...
    紀(jì)美閱讀 730評(píng)論 0 0
  • 在辛祝路拐到祝甸路的路口,立著一塊大石頭,上面赫然刻著兩個(gè)紅色大字“祝甸”,每次我坐公交從這里路過的時(shí)候都會(huì)興奮一...
    楊福江閱讀 1,170評(píng)論 12 11
  • 20170109 昨天小阿姨家女兒歡歡的寶寶呱呱墜地了,6斤半,很適中的體重,順產(chǎn)。 看人家生孩子總是那么快,而自...
    蕭蕭依舊閱讀 571評(píng)論 1 1
  • [背景]一年一度的教師節(jié)又來了,是自己轉(zhuǎn)行,第十個(gè)教師節(jié)。今天的教師節(jié)上表彰了許多優(yōu)秀的教師,優(yōu)秀的教育工作者。以...
    Herjin白龍馬閱讀 99評(píng)論 0 0

友情鏈接更多精彩內(nèi)容