欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

VueRouter代碼筆記

VueRouter

VueRouter基本使用

<!-- 引入對應(yīng)的模塊 -->
<script src="./static/vue.min.js"></script>
<script src="./static/vue-router.js"></script>

<div id="app">
    <div>
        <!-- 第三步:結(jié)合router-link和router-view調(diào)用 -->
        <router-link to="/">首頁</router-link>
        <router-link to="/login">登錄</router-link>
        <router-link to="/register">注冊</router-link>
        <router-view></router-view>
    </div>
</div>

<script>
    // Vue.use(VueRouter);   // 這個主要是在vue-cli會用到,這里可以不用填

        let Register = { template: '<div><h2>這是注冊頁面</h2></div>'
        let Login = { template: '<div><h2>這是登錄頁面</h2></div>'
        let Home = { template: '<div><h2>這是主頁面</h2></div>'

    // 第一步:實例化router對象路徑和頁面進行綁定對應(yīng)關(guān)系
    let router = new VueRouter({
      routes: [
        {  path: '/',  component: Home,  },
        { path: '/login',  component: Login, },
        { path: '/register', component: Register },
      ]
    })
    new Vue({
      el: "#app",
    // 第二步:vue根實例中注冊router對象
      router: router,
    })
  </script>

命名路由(name)

<div id="app">
        <div>
            <router-link :to="{ name: 'home'}">主頁</router-link>
            <router-link :to="{ name: 'login'}">登錄</router-link>
            <router-link :to="{ name: 'register'}">注冊</router-link>
            <router-view></router-view>
        </div>
</div>
<script>
        let Register = { template: '<div><h2>這是注冊頁面</h2></div>'
        let Login = { template: '<div><h2>這是登錄頁面</h2></div>'
        let Home = { template: '<div><h2>這是主頁面</h2></div>'

    let router = new VueRouter({
      routes: [
        {  name: 'home', path: '/',  component: Home,  },
        { name: 'login',  path: '/login',  component: Login, },
        { name: 'register', path: '/register', component: Register },
      ]
    })
    new Vue({
      el: "#app",
      router: router,
    })
  </script>

路由參數(shù)

<div id="app">
    <div>
        <router-link :to="{ name: 'home' }">主頁面</router-link>
        <router-link :to="{ name: 'userparams', params: { userId: 1} }">用戶參數(shù)params</router-link>
        <router-link :to="{ name: 'userquery', query: { userId: 2} }">用戶參數(shù) query</router-link>
        <router-view></router-view>
    </div>
</div>
<script>
    Vue.use(VueRouter);

    let Home = { template:'<div>這是主頁面</div>' }
    let UserParams = { template:'<div>這是用戶params</div>' }
    let UserQuery = { template:'<div>這是用戶query</div>' }

    let router = new VueRouter({
        routes: [
            {
                name: 'home',
                path: '/',
                component: Home,
            },
            {
                // 路由的參數(shù): /user/1 /user/2
                name: "userparams",
                path: '/user/:userId',
                component: UserParams
            },
            {
                // 路由參數(shù): /user?wenqipeng=111
                name: 'userquery',
                path: '/user',
                component: UserQuery
            },
        ]
    })

    new Vue({
        el: "#app",
        router: router
    })
</script>

子路由

<div id="app">
    <div>
        <router-link to="index">首頁</router-link>
        <router-link to="courses">課程頁面</router-link>
        <router-view></router-view>
    </div>
</div>
<script>
    let Index = { template: '<div><h2>這是首頁</h2></div>' }
    let Lightcourses = { template: '<div><h2>這是Lightcourses</h2></div>' }
    let Degreecourses = { template: '<div><h2>這是Degreecourses</h2></div>' }
    let Courses = { 
        template: `
            <div>
                <h2>這是課程頁</h2>
                <router-link to="lightcourses">輕客</router-link>
                <router-link to="degreecourses">學(xué)位課</router-link>
                <router-view></router-view>
            </div>'
        `
    }

    let router = new VueRouter({
        routes: [
            {
                name: 'index',
                path: '/index',
                component: Index,
            },
            {
                name: 'courses',
                path: '/courses',
                component: Courses,
                children: [   <!-- 路由 -->
                    {
                        name: 'lightcourses',
                        path: 'lightcourses',
                        component: Lightcourses
                    },
                    {
                        name: 'degreecourses',
                        path: 'degreecourses',
                        component: Degreecourses
                    },
                ]
            },
        ]
    })
    new Vue({
        el: "#app",
        router: router
    })
</script>

路由重定向 (redirect)

<div id="app">
    <div>
        <router-link to="/">首頁</router-link>
        <router-link to="/login">登錄</router-link>
        <router-link to="/pay">支付</router-link>

        <router-view></router-view>
    </div>
</div>

<script>

    let Index = { template: '<div><h2>這是首頁</h2></div>'}
    let Login = { template: '<div><h2>這是登錄頁面</h2></div>'}
    let Pay = { template: '<div><h2>這是支付頁面</h2></div>'}

    let router = new VueRouter({
        routes: [
            {
                path: '/',
                component: Index
            },
            {
                path: '/login',
                component: Login
            },
            {
                path: '/pay',
                // component: Pay,
                redirect: '/login'    <!-- 路由重定向 -->
            },
        ]
    })
    new Vue({
        el: "#app",
        router: router
    })

</script>

路由之鉤子函數(shù) (router.beforeEach)

<div id="app">
            <router-link :to="{ name: 'home' }">首頁</router-link>
            <router-link :to="{ name: 'login' }">登錄頁面</router-link>
            <router-link :to="{ name: 'pay' }">支付</router-link>
            <router-view></router-view>
    </div>

    <script>
            let Home = { template: '<div><h2>這是首頁頁面</h2></div>' }
            let Login = { template: '<div><h2>這是登錄頁面</h2></div>' }
            let Pay = { template: '<div><h2>這是支付頁面</h2></div>' }
            let router = new VueRouter({
                    routes: [ 
                            { name: 'home', path: '/', component: Home, },
                            { name: 'login', path: '/login', component: Login, },
                            { name: 'pay', path: '/pay', meta: { required_login: true }, component: Pay, },
                    ]
            });

            // 通過router對象的beforeEach(function(to, from, next))
            router.beforeEach(function (to, from, next) {
                 console.log("to: ", to);
                 console.log("from: ", from);
                 console.log("next: ", next);
                 if ( to.meta.required_login ) {
                         next('/login');
                 } else {
                         next();
                 }
            });

            new Vue({
                    el: "#app",
                    router: router,
            })
    </script>

文章題目:VueRouter代碼筆記
地址分享:http://aaarwkj.com/article28/pdidcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站Google、虛擬主機品牌網(wǎng)站建設(shè)、App設(shè)計網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
国产欧美成人精品第一区| 欧美日韩一区二区三区四区高清视频| 成人黄色小视频下载| 日韩中文字幕一二三| 高清av在线国产成人精品自拍| 国产精品无卡无在线播放| 日韩成人在线视频中文字幕| 国产成人综合精品久久| 日韩精品一二区电影| 日本人妻系列中文字幕| 国产一区二区三区性色| 九九国产精品免费视频| 日韩一区二区免费看视频| 欧美日韩台湾一区二区| 99久久精品国产熟女拳交| 夜夜嗨av一区二区三区| 日本欧美国产污黄在线观看 | 丰满人妻被猛烈进入中| 91出品国产福利在线| 亚洲av粉色一区二区三区| 国外男女性生活在线视频| 日本在线视频精品一区| 丰满人妻视频一二三区| 日韩新片一区二区三区| 色自拍偷拍另类欧洲美女| 亚洲天堂成人av蜜臀| 欧美三级亚洲三级日韩三级| 在线播放亚洲一区二区三区| 国产综合欧美日韩在线91| 加勒比人妻一区二区三区| 丰满人妻一区二区三区色| 欧美一区二区专区在线| 国产三级自拍视频在线观看网站| 男人一插就想射的原因| 日本人妻风俗店中文字幕| 日韩爱爱特级视频中文字幕| av天堂午夜精品蜜臀| 久久精品亚洲熟女av蜜謦| 香港精品国产三级国产av| 青青草原三区在线播放| 少妇性生活视频免费观看|