vue-router-template二級(jí)路由

1.通過vue-cli創(chuàng)建項(xiàng)目(項(xiàng)目名字不能大小意乓,同名下劃線分割)vue-router-template

  • 頁面和主鍵放在components,.....一般pages(主鍵)

2.更改config下的端口

3.修改App.vue

<template>
    <div id="app">
        <router-view />
    </div>
</template>

<script>
export default {
    name: 'App'
};
</script>

<style>
#app {
    width: 100%;
    background-color: #eee;
}
</style>

  • Index.vue
<template>
    <div>
        <div class="header">
            <div class="nav">
                <router-link to="/index" class="logo">我的班課</router-link>
                <router-link to="/task">任務(wù)中心</router-link>
                <router-link to="/lib">庫管理</router-link>
                <router-link to="/ucenter">個(gè)人中心</router-link>
                <router-link to="/sign">退出</router-link>
            </div>
        </div>
        <div class="content"><router-view /></div>
    </div>
</template>

<script>
export default {
    name: 'Index',
    data() {
        return {};
    }
};
</script>

<style>
.header {
    width: 100%;
    height: 80px;
    background-color: #fff;
    display: flex;
    align-items: center;
}
.nav{
    width: 80%;
    margin: 0 auto;
}
a{
    color: darkslategrey;
    font-size: 18pt;
    text-decoration: none;
    margin-right: 50px;
}
a:hover{
    color: rgb(0, 187, 221);
}
.logo{
    margin-right: 50%;
}
.content {
    width: 80%;
    margin: 0 auto;
    margin-top: 20px;
    height: 600px;
}
</style>

  • Lib.vue
<template>
    <div class="container">
        <div class="content"><router-view /></div>
        <div class="side-bar">
            <router-link to="/lib_exam">題庫</router-link>
            <router-link to="/lib_resources">資源庫</router-link>
            <router-link to="/lib_activity">活動(dòng)庫</router-link>
        </div>
    </div>
</template>

<script>
export default {
    name: 'Lib',
    data() {
        return {

        };
    }
};
</script>

<style scoped>
    .container{
        display: flex;
        width: 90%;
        margin: 0 auto;
    }
    .content{
        flex: 1 1 80%;
        text-align:center;
        background-color: #fff;
        padding-bottom: 20px;
    }   

    a{
        margin-top: 30px;
    }
    .side-bar{
        display: flex;
        flex-direction: column;
        background-color: #fff;
        margin-top: 20px;
        margin-left: 20px;
        flex: 1 1 20%;
    }
</style>

  • index.js
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
    mode: "history",
    routes: [{
            path: '/',
            redirect: 'index',
        },
        {
            //主頁
            path: '/index',
            redirect: 'course',
            component: resolve => require(['../components/Index.vue'], resolve),
            meta: {
                title: '主頁'
            },
            children: [{
                    //我的班課組件
                    path: '/course',
                    component: resolve => require(['../components/Course.vue'], resolve),
                    meta: {
                        title: '我的班課'
                    }
                },
                {
                    //任務(wù)中心
                    path: '/task',
                    component: resolve => require(['../components/Task.vue'], resolve),
                    meta: {
                        title: '任務(wù)中心'
                    }
                },
                {
                    //庫管理
                    path: '/lib',
                    component: resolve => require(['../components/Lib.vue'], resolve),
                    meta: {
                        title: '庫管理'
                    },
                    children:[
                        {
                            //題庫
                            path:'/lib_exam',
                            component:resolve => require(['../components/LibExam.vue'],resolve),
                            meta:{
                                title:'題庫'
                            }
                        },
                        {
                            //資源庫庫
                            path:'/lib_resources',
                            component:resolve => require(['../components/LibResources.vue'],resolve),
                            meta:{
                                title:'資源庫'
                            }
                        },
                        {
                            //活動(dòng)庫
                            path:'/lib_activity',
                            component:resolve => require(['../components/LibActivity.vue'],resolve),
                            meta:{
                                title:'活動(dòng)庫'
                            }
                        }
                    ]
                },
                {
                    //班課詳情組件
                    path: '/c/:id',
                    component: resolve => require(['../components/CourseDetail.vue'], resolve),
                    meta: {
                        title: '專題詳情'
                    }
                },
                {
                    // 個(gè)人中心組件
                    path: '/ucenter',
                    // redirect: 'user_infomation',
                    component: resolve => require(['../components/UCenter.vue'], resolve),
                    meta: {
                        title: '個(gè)人中心'
                    },
                    children: [{
                            //我的信息
                            path: '/user_infomation',
                            component: resolve => require(['../components/UserInfomation.vue'], resolve),
                            meta: {
                                title: '我的信息'
                            }
                        },
                        {
                            //用戶信息
                            path: '/user_profile',
                            component: resolve => require(['../components/UserProfile.vue'], resolve),
                            meta: {
                                title: '用戶信息'
                            }
                        },
                        {
                            //賬號(hào)安全
                            path: '/account_security',
                            component: resolve => require(['../components/AccountSecurity.vue'], resolve),
                            meta: {
                                title: '賬號(hào)安全'
                            }
                        }
                    ]
                },
            ]
        },
        {
            // 注冊(cè)登錄
            path: '/sign',
            component: resolve => require(['../components/Sign.vue'], resolve),
            meta: {
                title: '注冊(cè)登錄'
            },
            children: [
                {
                    path: '/sign_in',
                    component: resolve => require(['../components/SignIn.vue'], resolve),
                    meta: {
                        title: '登錄'
                    },
                },
                {
                    path: '/sign_up',
                    component: resolve => require(['../components/SignUp.vue'], resolve),
                    meta: {
                        title: '注冊(cè)'
                    },
                }
            ]
        }
    ]
})

  • 運(yùn)行結(jié)果
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末送悔,一起剝皮案震驚了整個(gè)濱河市爪模,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌洁段,老刑警劉巖共郭,帶你破解...
    沈念sama閱讀 219,366評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件除嘹,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡尉咕,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門蟆肆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來晦款,“玉大人缓溅,你說我怎么就攤上這事√彻郑” “怎么了?”我有些...
    開封第一講書人閱讀 165,689評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵更啄,是天一觀的道長居灯。 經(jīng)常有香客問我内狗,道長义锥,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,925評(píng)論 1 295
  • 正文 為了忘掉前任赂鲤,我火速辦了婚禮柱恤,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘泡孩。我一直安慰自己荚守,他們只是感情好练般,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,942評(píng)論 6 392
  • 文/花漫 我一把揭開白布薄料。 她就那樣靜靜地躺著,像睡著了一般摄职。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上蛔垢,一...
    開封第一講書人閱讀 51,727評(píng)論 1 305
  • 那天迫悠,我揣著相機(jī)與錄音,去河邊找鬼艺玲。 笑死鞠抑,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的搁拙。 我是一名探鬼主播法绵,決...
    沈念sama閱讀 40,447評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼礼烈,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼婆跑!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起滑进,我...
    開封第一講書人閱讀 39,349評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤扶关,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后搀庶,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體铜异,經(jīng)...
    沈念sama閱讀 45,820評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,990評(píng)論 3 337
  • 正文 我和宋清朗相戀三年咆蒿,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了蚂子。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,127評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡蒂破,死狀恐怖别渔,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情挟秤,我是刑警寧澤抄伍,帶...
    沈念sama閱讀 35,812評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站攀甚,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏秋度。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,471評(píng)論 3 331
  • 文/蒙蒙 一埠居、第九天 我趴在偏房一處隱蔽的房頂上張望事期。 院中可真熱鬧,春花似錦绎橘、人聲如沸唠倦。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽枷餐。三九已至苫亦,卻和暖如春毛肋,著一層夾襖步出監(jiān)牢的瞬間屋剑,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評(píng)論 1 272
  • 我被黑心中介騙來泰國打工孕讳, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留厂财,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,388評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像肪康,于是被迫代替她去往敵國和親撩穿。 傳聞我的和親對(duì)象是個(gè)殘疾皇子谒撼,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,066評(píng)論 2 355