element-ui 中的 NavMenu 导航菜单 el-menu-item标签 自定义默认被选中

  • 是选中的’/Book/HomePage’ 默认选中的
  • 至于这个’/Book/HomePage’ 就是 你 循环出来的 的值:index=“item.name”
<template>
  <div id="index">
     <el-menu :default-active="'/Book/HomePage'"
             router
             mode="horizontal"
             background-color="white"
             text-color="#222"
             active-text-color="red"
             style="min-width: 1300px">
      <el-menu-item v-for="(item,i) in navList"
                    :key="i"
                    :index="item.name">
        {{ item.navItem }}
      </el-menu-item>
    
     
      <a href="#nowhere"
         style="color: #222;float: right;padding: 20px;">更多功能</a>
      <i class="el-icon-menu"
         style="float:right;font-size: 45px;color: #222;padding-top: 8px"></i>
      <span style="position: absolute;padding-top: 20px;right: 43%;font-size: 20px;font-weight: bold">书籍是人类的进步的阶梯高尔基!!!</span>
    </el-menu>

    <div class="content"
         ref="content">
      <router-view />
    </div>
  </div>

</template>

<script>
export default {
  data() {
    return {
      navList: [
        { name: '/Book/HomePage', navItem: '首页' },
        { name: '/Book/jotter', navItem: '笔记本'},
        { name: '/Book/library', navItem: '图书馆'},
        { name: '/Book/user', navItem: '个人中心'},
      ],
    }
  },
  mounted() {
    this.$refs.content.style.height =
      document.documentElement.clientHeight - 62.22 + 'px' //设置高度
  },
  methods: {
    getUserInfo() {
      var serInfo = sessionStorage.getItem('userInfo')
      this.$store.commit('USER_SIGNIN', userInfo)
    },
    handleSelect(key, keyPath) {
        console.log(key, keyPath);
      }
  },
}
</script>

<style scoped>
#index {
  width: 100%;
  height: 100%;
}
#index .content {
  height: 100%;
}
</style>
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要修改 `NavMenu` 导航菜单里面 `sidebar-item`,需要按照以下步骤进行: 1. 在 `NavMenu` 找到需要修改的 `sidebar-item`,确定其 `name` 属性。 2. 在你的代码引入 `NavMenu` 组件。 3. 使用 `$refs` 获取 `NavMenu` 组件的实例。 4. 使用 `getItem()` 方法获取需要修改的 `sidebar-item` 的实例。 5. 修改该实例的属性,例如 `title`,`icon` 等。 6. 调用 `updateOpened()` 方法更新菜单。 以下是修改 `NavMenu` 导航菜单里面 `sidebar-item` 的示例代码: ```html <template> <div> <el-nav-menu ref="menu" :default-active="activeIndex" class="el-menu-vertical-demo" @select="handleSelect"> <template v-for="(item, index) in menuList"> <el-submenu v-if="item.children" :index="item.path" :key="index"> <template slot="title"> <i :class="item.icon"></i> <span slot="title">{{ item.title }}</span> </template> <el-menu-item v-for="(child, i) in item.children" :index="child.path" :key="i">{{ child.title }}</el-menu-item> </el-submenu> <el-menu-item v-else :index="item.path" :key="index"> <i :class="item.icon"></i> <span slot="title">{{ item.title }}</span> </el-menu-item> </template> </el-nav-menu> </div> </template> <script> import { mapState } from 'vuex'; export default { name: 'SidebarMenu', data() { return { activeIndex: '', menuList: [ { title: '首页', path: '/', icon: 'iconfont icon-home', }, { title: '文章', path: '/article', icon: 'iconfont icon-article', children: [ { title: '技术', path: '/article/tech', }, { title: '生活', path: '/article/life', }, ], }, ], }; }, mounted() { this.activeIndex = this.$route.path; }, methods: { handleSelect(index) { this.activeIndex = index; this.$router.push(index); }, }, computed: { ...mapState(['menu']), }, watch: { menu() { this.$nextTick(() => { // 获取需要修改的 sidebar-item 实例 const sidebarItem = this.$refs.menu.getItem('/article/tech'); // 修改该实例的属性 sidebarItem.title = '技术文章'; sidebarItem.icon = 'iconfont icon-tech'; // 更新菜单 this.$refs.menu.updateOpened(); }); }, }, }; </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值