el-menu 导航菜单 item 过多的显示问题

    <!-- PC menu -->
    <div class="kxb-hidden-small kxb-hidden-medium kxb-black-bg">
      <div class="kxb-fluid kxb-padding-bottom-0">
        <div class="kxb-col-12-9 kxb-col-medium-12-12">
          <div class="kxb-groupmenu">
            <div class="left">
              <i
                class="el-icon-arrow-left kxb-pointer"
                @click="menuleft"
                v-show="currentTabIndex"
              ></i>
            </div>
            <div class="menu pcmenu">
              <el-menu
                mode="horizontal"
                class="el-menu-vertical-demo"
                :default-active="tabActive"
              >
                <el-menu-item
                  index="首页"
                  v-show="0 >= currentTabIndex"
                  @click="tabActive = '首页'"
                  >首页</el-menu-item
                >
                <el-menu-item
                  @click="select(item)"
                  v-for="(item, index) in showTabs"
                  :key="item._id"
                  :index="item.title"
                  v-show="index + 1 >= currentTabIndex && currentTabIndex + 9 > index + 1"
                >
                  <!-- 9个tab默认显示 -->
                  {{ item.name ? item.name : item.title }}</el-menu-item
                >
              </el-menu>
            </div>
            <div class="right">
              <i
                class="el-icon-arrow-right kxb-pointer"
                @click="menuright"
                v-show="showTabs.length - currentTabIndex + 1 > 9"
              >
                <!-- 9个tab默认显示 -->
              </i>
            </div>
          </div>
        </div>
        <div
          class="kxb-col-12-3 kxb-col-medium-12-12 kxb-center"
          style="padding-top: 15px"
        >
          <el-button
            v-if="!isApplicant && this._id"
            type="primary"
            size="mini"
            @click="toSignUp('add')"
            >参会报名</el-button
          >
          <el-button
            v-if="isApplicant && this._id"
            type="primary"
            size="mini"
            @click="toSignUp('modify')"
            >修改报名</el-button
          >
          <a href="/meetingInfo/MeetingAttend" target="_blank" style="margin-left: 10px"
            ><el-button type="primary" plain size="mini">我的参会</el-button></a
          >
        </div>
      </div>
    </div>
    <!-- Mobile and Paid menu -->
    <div
      class="mobilemenu kxb-padding-top-half kxb-right kxb-hidden-large kxb-hidden-xlarge"
    >
      <el-dropdown @command="select" trigger="click">
        <span class="mobile-tab">
          <span></span>
          <span></span>
          <span></span>
          <!-- 空的 三个 span 不要删除,是用来画 tab 手机版的三条横线的 -->
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item index="home" command="1">首页</el-dropdown-item>
          <el-dropdown-item v-for="item in showTabs" :key="item._id" :command="item">{{
            item.name ? item.name : item.title
          }}</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
/*tab part begin*/
.kxb-groupmenu {
  width: 100%;
  display: flex;
  margin-bottom: 0;

  .left,
  .right {
    width: 15px;
    color: #fff;
    font-size: 20px;
  }
  .left {
    text-align: right;
  }

  /* tab 整体高度设置 */

  &,
  .left,
  .right,
  /deep/ .el-menu--horizontal > .el-menu-item {
    height: 60px;
    line-height: 60px;
  }

  .menu {
    text-align: center;
    padding: 0;
    font-size: 1.42rem;

    /deep/ .el-menu--horizontal {
      display: inline-block;
      border-bottom: none;
      background-color: #000;
      width: 100%;
    }

    /deep/ .el-menu--horizontal > .el-menu-item {
      width: var(--showTabNum, 11.11%);
      /*每次显示 8 个 tab   <!-- 9个tab默认显示 -->*/
      color: white;
      font-size: 1.14rem;
      border-bottom: none;
    }

    /deep/ .el-menu--horizontal > .el-menu-item.is-active,
    /deep/ .el-menu--horizontal > .el-menu-item.is-active:hover {
      /*高亮后 item 样式 */
      background-color: #1b57d6;
    }

    /deep/ .el-menu--horizontal > .el-menu-item:hover {
      /*鼠标滑过 item 样式 */
      color: #1fb9b7;
      background-color: #000;
    }
  }
}

.mobilemenu {
  padding: 10px 15px 5px 0;
  .mobile-tab {
    border: 1px solid #333;
    border-radius: 2px;
    display: inline-block;
    height: 32px;
    width: 38px;
    padding: 7px 8px 0;
    box-sizing: border-box;
    & > span {
      border-bottom: 2px solid #333;
      margin-bottom: 4px;
      display: block;
    }
  }
}
/*tab part end*/
if (this.showTabs.length < 9) {
              //如果 tab 小于 8个 那么 tab 的宽度将不再是 12.5%  <!-- 原有8个tab默认显示,现改为10个 -->
              let value = 100 / (this.showTabs.length + 1) + "%";
              document.body.style.setProperty("--showTabNum", value);
              //这里 + 1 是因为 tab 的宽度计算要算上首页
            }

Bluma 导航 显示过多的解决方案

<!-- Tab 正常样式 -->
<template>
  <section class="section kxb-tab-color has-text-white px-1 py-0 is-relative">
    <!-- Tab PC version Begin -->
    <div class="is-hidden-mobile is-hidden-tablet-only">
      <div
        class="kxb-pc-menu is-flex is-flex-direction-row is-justify-content-space-between"
      >
        <div class="kxb-width-small has-text-centered">
          <i
            v-show="currentTabIndex"
            class="el-icon-arrow-left is-clickable"
            @click="menuLeft"
          >
          </i>
        </div>
        <div class="has-text-centered is-flex-grow-1">
          <div class="tabs is-centered">
            <ul>
              <li
                v-show="0 >= currentTabIndex"
                :class="{ 'is-active': tab == '-1' }"
              >
                <a @click="tabChangeHandler('-1')">{{
                  $t('conference.home')
                }}</a>
              </li>
              <li
                v-for="(item, index) in conference.modules"
                v-show="
                  index + 1 >= currentTabIndex &&
                  currentTabIndex + showTabNumber > index + 1
                "
                :key="item.id"
                :class="{ 'is-active': tab == item.type }"
              >
                <a @click="tabChangeHandler(item.type, item.id)">{{
                  ch ? item.name : item.nameEn
                }}</a>
              </li>
            </ul>
          </div>
        </div>
        <div class="kxb-width-small has-text-centered">
          <i
            v-show="
              conference.modules.length - currentTabIndex + 1 > showTabNumber
            "
            class="el-icon-arrow-right is-clickable"
            @click="menuRight"
          >
          </i>
        </div>
      </div>
    </div>
    <!-- Tab PC version End -->
    <!-- Tab Mobile version Begin -->
    <div
      class="is-hidden-desktop-only is-hidden-widescreen-only is-hidden-fullhd dropdown kxb-mobile-menu is-right"
      :class="{ 'is-active': dropdownShow }"
    >
      <div class="dropdown-trigger">
        <button
          class="button"
          aria-haspopup="true"
          aria-controls="dropdown-menu"
          @click="dropdownShow = !dropdownShow"
        >
          <span class="mobile-tab">
            <span></span>
            <span></span>
            <span></span>
            <!-- 空的 三个 span 不要删除,是用来画 tab 手机版的三条横线的 -->
          </span>
        </button>
      </div>
      <div id="dropdown-menu" class="dropdown-menu" role="menu">
        <div class="dropdown-content">
          <a
            class="dropdown-item"
            :class="{ 'is-active': tab == '-1' }"
            @click="tabChangeHandler('-1')"
          >
            {{ $t('conference.home') }}
          </a>
          <a
            v-for="(item, index) in conference.modules"
            :key="item.id"
            class="dropdown-item"
            :class="{ 'is-active': tab == item.type }"
            @click="tabChangeHandler(item.type, item.id)"
          >
            {{ ch ? item.name : item.nameEn }}
          </a>
        </div>
      </div>
    </div>
    <!-- Tab Mobile version End -->
  </section>
</template>
<script lang="ts">
import Vue from 'vue';

type DataType = {
  currentTabIndex: number;
  tab: string;
  showTabNumber: number;
  dropdownShow: boolean;
};

type MethodsType = {
  tabChangeHandler(type: string, id?: string): void;
  menuLeft(): void;
  menuRight(): void;
};

type ComputedType = {};

type propType = {
  conference: Object;
  ch: Boolean;
};

export default Vue.extend<DataType, MethodsType, ComputedType, propType>({
  name: 'TabNormal',
  props: {
    conference: {
      type: Object,
      default() {
        return {};
      },
    },
    ch: {
      type: Boolean,
      default() {
        return true; // 页面语言默认汉语
      },
    },
  },
  data: () => ({
    tab: '-1', // 默认展示首页 用于判断高亮
    currentTabIndex: 0, // 默认展示首页 用于左边右边箭头和中间 item show/hide 的 判断
    showTabNumber: 4, // 默认显示的 tab 的数量
    dropdownShow: false,
  }),
  mounted() {},
  methods: {
    menuLeft() {
      this.currentTabIndex--;
    },
    menuRight() {
      this.currentTabIndex++;
    },
    tabChangeHandler(type: string, id?: string) {
      this.tab = type;
      this.$emit('tabChangeHandler', type, id);
    },
  },
});
</script>
<style lang="sass" scoped>
.kxb-tab-color
  background: var(--main-color)


/*tab part begin*/
.kxb-pc-menu
  width: 100%
  display: flex

  .kxb-width-small
    width: 150px
    padding-top: 6px

  .tabs
    ul
      border-bottom-color: #1a73e8
    a
      color: #fff
      border-bottom-color: #1a73e8
    a:hover
      border-bottom-color: #1a73e8

    li.is-active
      a
        color: #ff1
        border-bottom-color: #1a73e8

.kxb-mobile-menu
  background-color: none
  border: none
  position: absolute
  right:10px
  top:15px
  .button
    background-color: rgba(0, 0, 0, 0) !important
  .mobile-tab
    span
      border-bottom: 2px solid #333
      margin-top: 4px
      margin-bottom: 2px
      display: block
      width: 25px
</style>

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 在 Vue.js 中使用 element-ui 组件库的 el-menu 组件创建递归菜单时,可以在菜单项的模板中使用 el-menu-item-group 组件来表示一组子菜单。 要在 el-menu 中使用递归菜单,需要在其模板中使用一个循环来遍历菜单数据,并为每个菜单项使用 el-menu-item 组件。如果该菜单项有子菜单,则可以在该菜单项下使用 el-menu-item-group 组件,并将该菜单项的子菜单数据作为 el-menu-item-group 组件的 children 属性来递归渲染。 例如,假设你有以下菜单数据: ``` const menuData = [ { label: '菜单 1', children: [ { label: '子菜单 1-1' }, { label: '子菜单 1-2' }, ] }, { label: '菜单 2', children: [ { label: '子菜单 2-1' }, { label: '子菜单 2-2', children: [ { label: '子菜单 2-2-1' }, { label: '子菜单 2-2-2' }, ] }, ] } ] ``` 你可以在 el-menu 模板中使用以下代码来渲染递归菜单: ``` <el-menu> <template v-for="item in menuData"> <el-menu-item v-if="!item.children" :key="item.label">{{ item.label }}</el-menu-item> <el-menu-item-group v-else :key="item.label" :title="item.label"> <template v-for="subItem in item.children"> <el-menu-item v-if="!subItem.children" :key="subItem.label">{{ subItem.label }}</el-menu-item> <el-menu-item-group v-else :key="subItem.label" :title="subItem. ### 回答2: el-menuElement UI中的一个组件,用于创建菜单导航el-menu-item-group是el-menu的子组件,用于将多个el-menu-item组合成一个组。 对于el-menu递归菜单,可以使用递归函数来处理el-menu-item-group。首先,在父组件中创建一个递归函数,用于遍历菜单数据。然后,在el-menu中使用该递归函数来渲染菜单项。 具体处理步骤如下: 1. 父组件中,定义一个递归函数,例如renderMenu,接收一个菜单数据作为参数。在该函数中,遍历菜单数据,判断每个菜单项是否是el-menu-item-group。 2. 如果菜单项是el-menu-item-group,则递归调用renderMenu函数,将菜单项的子菜单数据作为参数传入。在el-menu-item-group中使用renderMenu来渲染子菜单项。 3. 如果菜单项不是el-menu-item-group,则直接渲染el-menu-item,并将菜单项的其他属性作为参数传入。 4. 在el-menu中使用renderMenu函数来渲染菜单项,将菜单数据作为参数传入。 通过以上步骤,可以实现对el-menu递归菜单中的el-menu-item-group的处理。递归函数可以遍历菜单数据,判断每个菜单项的类型,并进行渲染。这样就可以动态生成el-menu菜单导航,并且可以支持多级菜单的嵌套结构。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值