国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

vue子路由跳轉實現tab選項卡

2024-05-06 15:36:39
字體:
來源:轉載
供稿:網友

現在很多的后臺管理系統都采用tab選項卡的布局,左邊是導航欄固定,右邊是對應的頁面,每次點擊左邊的導航標題,只有右面的對應頁面再切換,而vue要做tab選項卡,推薦使用<router-link></router-link>實現a標簽的效果,然后使用<router-view></router-view>實現插槽的效果,把對應的頁面 "塞" 進去,具體實現看下面的案例:

1、這是tab選項卡的頁面,布局就不說了,主要是<router-link :to="a.url" :key="index" v-for="(a,index) in Data">{{a.title}}</router-link>,其中to指向你要跳轉的路徑,這是關鍵,而<router-view></router-view>就是最終其他子頁面要顯示的地方

<template>  <div class="index-box">    <nav>      <h1>導航</h1>      <!-- 所有的導航標題,進行路由跳轉指向 -->      <router-link :to="a.url" :key="index" v-for="(a,index) in Data">{{a.title}}</router-link>    </nav>    <div class="content">      <!-- 路由插槽:路由跳轉的位置 -->      <router-view></router-view>    </div>   </div></template> <script>  import navData from "../../static/data/nav"  export default {    name: "Index",    data(){      return {        Data:[]      }    },    methods:{      init(){        this.Data = navData.navData;      }    },    created(){      this.init();    }  }</script> <style scoped>  /* 容器 */  .index-box{    width: 100%;    height: 100%;    background: #212224;    display: flex;  }  /* 左側導航條 */  nav{    width: 260px;    height: 100%;    background: #323437;    overflow: hidden;    float: left;  }  /* 導航 */  nav h1{    color: #f2ffff;    margin: 10px 0 10px 10px;  }  /* 導航標題 */  nav a{    display: block;    width: 100%;    height: 45px;    color: #f2ffff;    background: #2e3033;    padding-left: 10px;    line-height: 45px;    font-size: 20px;    margin-bottom: 10px;  }  /* 右側內容 */  .content{    flex: 1;    padding: 20px;  }</style>

2、路由配置

這個案例中,默認顯示的就是我tab選項卡的頁面,所以其他子頁面我就以這個頁面配置的子路由

如果有其他需求,就再需要的地方配置子路由即可

import Vue from 'vue'import Router from 'vue-router'// 首頁import Tab from "../pages/Tab"http:// 頁面一import PageOne from "../pages/PageOne"http:// 頁面二import PageTwo from "../pages/PageTwo"http:// 頁面三import PageThree from "../pages/PageThree" Vue.use(Router); export default new Router({ routes: [  {    // 默認顯示的頁面    path: '/',    name: 'Tab',    component: Tab,    children:[      {          // 子路由中默認顯示的頁面        path: '',        name: 'PageOne',        component: PageOne      },      {        path: 'PageTwo',        name: 'PageTwo',        component: PageTwo      },      {        path: 'PageThree',        name: 'PageThree',        component: PageThree      }    ]  } ]})            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 建平县| 乐山市| 离岛区| 合山市| 曲沃县| 张家口市| 新沂市| 右玉县| 昌平区| 红桥区| 新泰市| 苏尼特右旗| 十堰市| 长丰县| 永安市| 炎陵县| 南漳县| 轮台县| 郎溪县| 抚松县| 苍南县| 九龙城区| 剑川县| 泰和县| 丹巴县| 桓台县| 抚顺县| 北海市| 东兴市| 义马市| 尚义县| 鹰潭市| 晋江市| 诏安县| 罗山县| 石城县| 乃东县| 松江区| 县级市| 丽水市| 沂南县|