2018-09-24(vue指令)路由嵌套

vue指令

v-for=''(循環(huán)數(shù)組 對(duì)象 數(shù)組對(duì)象)

v-model=''(雙向數(shù)據(jù)綁定,用于表單元素)

v-on:click='alt函數(shù)名'

v-show(控制元素的顯示和隱藏使用display:none隱藏)

v-if (visibility:hidden;隱藏)

v-else

v-else-if

v-bind:src='值'

補(bǔ)充:

①:v-html=' ' ②:v-text=' '

③:v-once(只綁定一次)④:v-pre(原樣輸出)⑤:v-cloak

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model='name'>
        <h2 v-html='name'>{{name}}</h2>
        <p v-text='name'>{{name}}</p>
        <h1 v-once>{{name}}</h1>
        <h5 v-pre>{{name}}</h5>
    </div>
    <script src="vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:{
                name:'hello'
            }
        })
    </script>
</body>
</html>

屏幕展示:①能識(shí)別標(biāo)簽、②按書(shū)寫(xiě)輸出、③只綁定一次、④按原樣輸出


1.png
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        [v-cloak]{
            display: none;
        }
    </style>
</head>
<body>
    <div id="app">
        <h1 v-cloak>{{msg}}</h1>
    </div>
    <script src="vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:{
                msg:'hello'
            },
            beforeMount:function(){
                alert('beforeMount')
            }
        })
    </script>
</body>
</html>

屏幕展示:點(diǎn)擊按鈕


2.png
3.png

路由樣式

vue-router

vue的核心插件vue-router.js

根據(jù)不同的url訪問(wèn)不同的頁(yè)面,創(chuàng)建單頁(yè)面SPA應(yīng)用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        /*.router-link-active{
            color: orange
        }*/
        .a{
            color: palegreen
        }
    </style>
</head>
<body>
    <div id="app">
        <router-link to='/home'>首頁(yè)</router-link>
        <router-link to='/user'>用戶頁(yè)</router-link>
        
        <router-view></router-view>
    </div>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <script>
        var Home={
            template:`
                <div>
                    <h1>這是一個(gè)首頁(yè)</h1>
                    <p>這是一句話</p>
                </div>
            `
        }
        
        var User={
            template:`
                <h1>這是一個(gè)用戶頁(yè)</h1>
            `
        }
        
        const routes=[
            {path:'/',component:Home},
            {path:'/home',component:Home},
            {path:'/user',component:User}
        ]
        
        const router=new VueRouter({
            routes:routes,
            linkActiveClass:'a'
        })
        
        new Vue({
            el:'#app',
            router:router
        })
    </script>
</body>
</html>

屏幕展示:
4.png

5.png

路由嵌套

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .router-link-active{
            color: orange
        }
    </style>
</head>
<body>
    <div id="app">
        <router-link to='/home'>首頁(yè)</router-link>
        <router-link to='/index'>用戶頁(yè)</router-link>
        <router-view></router-view>
    </div>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <script>
        var Home={
            template:`
                <h1>這是首頁(yè)①</h1>
            `
        }
        
        var Index={
            template:`
                <div>
                    <h1>這是用戶頁(yè)②</h1>
                <ul>
                    <li>
                        <router-link to='/index/a'>注冊(cè)</router-link>
                    </li>
                    <li>
                        <router-link to='/index/b'>登錄</router-link>
                    </li>
                </ul>
                <router-view></router-view>
                </div>
            `
        }
        
        var A={
            template:`
                <h2>這是注冊(cè)</h2>
            `
        }
        
        var B={
            template:`
                <h2>這是登錄</h2>
            `
        }
        
        const routes=[
            {path:'/',component:Home},
            {path:'/home',component:Home},
            {
                path:'/index',
                component:Index,
                children:[
                    {path:'a',component:A},
                    {path:'b',component:B}
                ]
            }
        ]
        
        const router=new VueRouter({
            routes:routes
        })
        
        new Vue({
            el:'#app',
            router:router
        })
    </script>
</body>
</html>

屏幕展示:
6.png
7.png
?著作權(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)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • # 傳智播客vue 學(xué)習(xí)## 1. 什么是 Vue.js* Vue 開(kāi)發(fā)手機(jī) APP 需要借助于 Weex* Vu...
    再見(jiàn)天才閱讀 3,812評(píng)論 0 6
  • ## 框架和庫(kù)的區(qū)別?> 框架(framework):一套完整的軟件設(shè)計(jì)架構(gòu)和**解決方案**。> > 庫(kù)(lib...
    Rui_bdad閱讀 3,158評(píng)論 1 4
  • 一:什么是閉包?閉包的用處? (1)閉包就是能夠讀取其他函數(shù)內(nèi)部變量的函數(shù)。在本質(zhì)上,閉包就 是將函數(shù)內(nèi)部和函數(shù)外...
    xuguibin閱讀 10,068評(píng)論 1 52
  • 《生命的不可思議》文字精粹版(三) 讀書(shū)會(huì) | 一千個(gè)哈姆雷特 2017.08.07 (包含章節(jié):第十三章—第十七...
    一顆楊梅閱讀 1,327評(píng)論 0 0
  • 六月落了一天的狐貍雨太陽(yáng)是個(gè)大懶蟲(chóng)到了傍晚才睡醒天空被洗成極淡的藍(lán)色云被卷在樹(shù)梢上像童年的醇奶和棒冰想向哆啦A夢(mèng)要...
    栗子_栗子閱讀 323評(píng)論 2 4

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