ant-design-vue icon indicating copy to clipboard operation
ant-design-vue copied to clipboard

使用循环生成a-menu-item选择默认的key不生效

Open linzehai0801 opened this issue 1 year ago • 3 comments
trafficstars

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.

Version

undefined

Environment

Vue3

Reproduction link

https://www.antdv.com/components/layout-cn

Steps to reproduce

{{ menu.id }} {{ menu.title }} const collapsed = ref(false); const selectedKeys = ref(['1']); { id: 1, icon: 'PieChartOutlined', title: '展示中心', tube: '', 'menu_url': '/uric/show_center', children: [] }, { id: 2, icon: 'DesktopOutlined', title: '资产管理', 'menu_url': '/uric/host', children: [] },

What is expected?

期望const selectedKeys = ref(['1']);时会被默认选中

What is actually happening?

没有选中任何

linzehai0801 avatar Apr 10 '24 16:04 linzehai0801

id改成 ‘1’ 试试

qppq54s avatar Apr 11 '24 07:04 qppq54s

image

    <div style="float: right;padding-right: 20px">
      <a-avatar :size="32">
        <template #icon>
          <UserOutlined/>
        </template>
      </a-avatar>
    </div>
  </a-layout-header>
  <a-layout-content style="margin: 0 16px">
    <!--        <a-breadcrumb style="margin: 16px 0">-->
    <!--          <a-breadcrumb-item>主页</a-breadcrumb-item>-->
    <!--          <a-breadcrumb-item>Bill</a-breadcrumb-item>-->
    <!--          <a-breadcrumb-item>aaa</a-breadcrumb-item>-->
    <!--        </a-breadcrumb>-->
    <a-breadcrumb style="margin: 16px 0">
      <a-breadcrumb-item>主页</a-breadcrumb-item>
      <template v-for="item in menu_list" :key="item.id">
        <a-breadcrumb-item v-if="item.id === selectedKeys[0]">{{ item.title }}</a-breadcrumb-item>
      </template>
    </a-breadcrumb>

    <div :style="{ padding: '24px', background: '#fff', minHeight: '360px' }">
      <router-view></router-view>
    </div>
  </a-layout-content>
  <a-layout-footer style="text-align: center">
    Ant Design ©2024 Created by Ant UED
  </a-layout-footer>
</a-layout>
这是我的脚本麻烦帮忙看看

linzehai0801 avatar Apr 11 '24 08:04 linzehai0801

@linzehai0801 我的意思是,你的id是数字,但是selectKeys里的是字符串,这两个要保持统一,把你menu_list里的id:1改成id: '1'这样

qppq54s avatar Apr 11 '24 09:04 qppq54s

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Jun 11 '24 02:06 github-actions[bot]