溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果的方法

發(fā)布時間:2022-03-02 14:33:55 來源:億速云 閱讀:682 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“vue子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果的方法”,在日常操作中,相信很多人在vue子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果的方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”vue子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果的方法”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

tab選項卡的布局在項目中是很常見的,在后臺管理系統(tǒng)中左邊是導(dǎo)航欄固定,右邊是對應(yīng)的頁面,每次點擊左邊的標題,只有右面的對應(yīng)頁面在切換,而vue要做tab選項卡,推薦使用實現(xiàn)a標簽的效果,然后使用實現(xiàn)插槽的效果,把對應(yīng)的頁面 “塞” 進去,具體實現(xiàn)看下面的案例:

vue文件

<template>
    <div class="box">
        <!-- nav標題,路由指向 -->
       <div class="left">
           <router-link :to="item.src" v-for="(item,index) in navData" :key="index">{{item.title}}</router-link>
       </div>
       <div class="right">
           <!-- 路由跳轉(zhuǎn)的位置 -->
           <router-view></router-view>
       </div>
    </div>
</template>
<script>
export default {
    name:"Index",
    data(){
        return{
            navData:[
                {
                    title:"title一",
                    src:"/"
                },
                {
                    title:"title二",
                    src:"/nav2"
                },
                {
                    title:"title三",
                    src:"/nav3"
                }
            ]
        }
    }
}
</script>
<style scoped>
    .box{
        width: 100%;
        height: 100%;
        display: flex;
        background: rgba(0,0,0,.8)
    }
    .left{
        width:200px;
        height: 100%;
        text-align: center;
        background: rgba(0,0,0,.4);
        padding: 20px;
    }
    .left a{
        text-decoration: none;
        display: block;
        margin-top: 20px;
        width: 100%;
        color: #fff;
    }
    .right{
        flex: 1;
        padding: 20px;
        color: #fff;
    }
</style>

router.js

import Vue from 'vue'
import Router from 'vue-router'
import Index from './views/Index.vue'
import nav1 from './components/Index/nav1.vue'
import nav2 from './components/Index/nav2.vue'
import nav3 from './components/Index/nav3.vue'
Vue.use(Router)

export default new Router({
//去掉#
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      //name: 'Index',
      component: Index,
      children:[
        {
          path:'',
          name:'nav1',
          component:nav1
        },
        {
          path:'nav2',
          name:'nav2',
          component:nav2
        },
        {
          path:'nav3',
          name:'nav3',
          component:nav3
        }
      ]
    }
  ]
})

注意:當(dāng)在router.js中的routes中寫上name: 'Index',時在控制臺會有下面的警告,所以可以刪掉此句。

vue子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果的方法

右邊要顯示頁面的內(nèi)容

<!--  nav1.vue-->
    <template>
    <div>
        這是nav1
    </div>
</template>


<!--  nav2.vue-->
    <template>
    <div>
        這是nav2
    </div>
</template>


<!--  nav3.vue-->
    <template>
    <div>
        這是nav3
    </div>
</template>

效果圖

vue子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果的方法

簡單的子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果就實現(xiàn)啦

到此,關(guān)于“vue子路由跳轉(zhuǎn)實現(xiàn)tab選項卡效果的方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI