最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue使用element-ui實現(xiàn)菜單導(dǎo)航

 更新時間:2021年09月27日 11:43:15   作者:簡單碼  
這篇文章主要為大家詳細介紹了Vue使用element-ui實現(xiàn)菜單導(dǎo)航,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue使用element-ui實現(xiàn)菜單導(dǎo)航的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

目錄截圖

安裝vue-router 和 element-ui

vue-route是官方路由導(dǎo)航,element-ui是餓了么封裝的基于vue的組件庫

npm install vue-router --save
npm install element-ui --save

關(guān)閉ESLint檢查

新增配置文件src/vue.config.js 文件

module.exports = {
    lintOnSave: false
}

src/main.js

在main.js里引入vue-router 和 element-ui。
創(chuàng)建兩個頁面組件,電影和小說。
定義路由映射。
路由改成h5模式,去掉難看的#符號。

import Vue from 'vue'
import App from './App.vue'

import VueRouter from 'vue-router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'


import movie from './components/movie.vue'
import novel from './components/novel.vue'

Vue.config.productionTip = false

Vue.use(VueRouter)
Vue.use(ElementUI);

const routes = [
  { path: '/movie', component: movie },
  { path: '/novel', component: novel }
]

// 3. 創(chuàng)建 router 實例,然后傳 `routes` 配置
// 你還可以傳別的配置參數(shù), 不過先這么簡單著吧。
const router = new VueRouter({
  mode: 'history',  //h5模式
  routes // (縮寫) 相當(dāng)于 routes: routes
})

new Vue({
  render: h => h(App),
  router
}).$mount('#app')

src/comments/movie.vue

電影頁面組件

<template>
  <div>    
    movie頁面
  </div>
</template>

<script>
export default {
  name: 'movie' 
}
</script>


<style scoped>

</style>

src/comments/novel.vue

小說頁面組件

<template>
  <div>
    novel頁面
  </div>
</template>

<script>
export default {
  name: 'novel'  
}
</script>
<style scoped>

</style>

src/comments/NavMenu.vue

導(dǎo)航組件。這里使用了element-ui的菜單組件。navMenuData模擬了我們菜單的數(shù)據(jù)。屬性default-active代表當(dāng)前選中的菜單,router屬性代表index自動當(dāng)成路由路徑。

v-for循環(huán)生成菜單,在template標(biāo)簽中寫v-for,不會一直復(fù)制當(dāng)前的template。

看別人博客都是:default-active="$route.path",我這里多了個/。所以在mounted生命周期里去除/。

<template>
  <div id="NavMenu">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      router
    >
      <!-- 
      <el-menu-item index="1">電影</el-menu-item>
      <el-menu-item index="2">小說</el-menu-item>
      <el-submenu index="3">
        <template slot="title">我的工作臺</template>
        <el-menu-item index="3-1">選項1</el-menu-item>
        <el-menu-item index="3-2">選項2</el-menu-item>
        <el-menu-item index="3-3">選項3</el-menu-item>
        <el-submenu index="3-4">
          <template slot="title">選項4</template>
          <el-menu-item index="3-4-1">選項1</el-menu-item>
          <el-menu-item index="3-4-2">選項2</el-menu-item>
          <el-menu-item index="3-4-3">選項3</el-menu-item>
        </el-submenu>
      </el-submenu> 
      -->

      <template v-for="item in navMenuData">
        <el-menu-item :index="item.index" v-if="!item.child">{{item.name}}</el-menu-item>

        <el-submenu :index="item.index" v-if="item.child">
          <template slot="title">{{item.name}}</template>
          <template v-for="item2 in item.child">
            <el-menu-item :index="item2.index">{{item2.name}}</el-menu-item>
          </template>
        </el-submenu>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "NavMenu",
  data() {
    return {
      activeIndex: "movie",     
      navMenuData: [
        { index: "movie", name: "電影" },
        { index: "novel", name: "小說" },
        {
          index: "2",
          name: "我的工作臺",
          child: [{ index: "2-1", name: "選項1" },{ index: "2-2", name: "選項2" },{ index: "2-3", name: "選項3" }]
        },
       
      ]
    };
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    }
  },
  mounted(){         
      console.log(this.activeIndex)        
      console.log(this.$route.path)      
      this.activeIndex = this.$route.path.substring(1,this.$route.path.length);     

  }
};
</script>

<style scoped>
</style>

src/App.vue

這里使用了element-ui的容器布局,引入了自己寫的NavMenu菜單組件。

<template>
  <div id="app">
    <el-container>
      <el-header>
        <NavMenu></NavMenu>
      </el-header>
      <el-main>
         <router-view></router-view> <!--路由出口 -->
      </el-main>
      <el-footer>Footer</el-footer>
    </el-container>
  </div>
</template>

<script>
import NavMenu from "./components/NavMenu.vue";

export default {
  name: "app",
  components: {
    NavMenu
  }
};
</script>

<style scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  height: 100px;
  padding: 0px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

</style>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue-photo-preview圖片預(yù)覽失效的問題及解決

    vue-photo-preview圖片預(yù)覽失效的問題及解決

    這篇文章主要介紹了vue-photo-preview圖片預(yù)覽失效的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue實現(xiàn)簡單的MVVM框架

    vue實現(xiàn)簡單的MVVM框架

    這篇文章給大家分享了基于vue實現(xiàn)一個簡單的MVVM框架的相關(guān)內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。
    2018-08-08
  • vueJs實現(xiàn)DOM加載完之后自動下拉到底部的實例代碼

    vueJs實現(xiàn)DOM加載完之后自動下拉到底部的實例代碼

    這篇文章主要介紹了vueJs實現(xiàn)DOM加載完成之后自動下拉到底部的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-08-08
  • vue語法自動轉(zhuǎn)typescript(解放雙手)

    vue語法自動轉(zhuǎn)typescript(解放雙手)

    這篇文章主要介紹了vue語法自動轉(zhuǎn)typescript,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • vue修改數(shù)據(jù)視圖更新原理學(xué)習(xí)

    vue修改數(shù)據(jù)視圖更新原理學(xué)習(xí)

    這篇文章主要為大家介紹了vue修改數(shù)據(jù)視圖更新原理學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-11-11
  • 淺談Vue3 Composition API如何替換Vue Mixins

    淺談Vue3 Composition API如何替換Vue Mixins

    這篇文章主要介紹了淺談Vue3 Composition API如何替換Vue Mixins,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • vue-auto-focus: 控制自動聚焦行為的 vue 指令方法

    vue-auto-focus: 控制自動聚焦行為的 vue 指令方法

    今天小編就為大家分享一篇vue-auto-focus: 控制自動聚焦行為的 vue 指令方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • vue實現(xiàn)條件疊加搜索的解決方法

    vue實現(xiàn)條件疊加搜索的解決方法

    這篇文章主要為大家詳細介紹了vue實現(xiàn)條件疊加搜索的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • 解決vue表單為空也能提交的問題

    解決vue表單為空也能提交的問題

    這篇文章主要介紹了解決vue表單為空也能提交的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • 解析Vue.js中的組件

    解析Vue.js中的組件

    組件(Component)是 Vue.js 最強大的功能之一。組件可以擴展 HTML 元素,封裝可重用的代碼。這篇文章主要介紹了vue.js 中的組件,需要的朋友參考下
    2018-02-02

最新評論

华阴市| 杨浦区| 财经| 常熟市| 石家庄市| 土默特左旗| 昭平县| 洛川县| 华宁县| 新昌县| 乐昌市| 洛川县| 新疆| 泗水县| 阿克苏市| 西乌| 班戈县| 乾安县| 邵武市| 惠东县| 黔东| 江达县| 宜城市| 陇川县| 峨眉山市| 任丘市| 芦溪县| 镇赉县| 阜康市| 哈尔滨市| 财经| 烟台市| 哈巴河县| 漳浦县| 湖南省| 镇巴县| 河东区| 明溪县| 武川县| 安丘市| 板桥市|