[Vue warn]: Invalid prop: type check failed for prop “index“.Expected String with value “145“...

本文讲述了在使用Element Plus的el-menu组件时遇到警告的问题,通过将index属性从数值类型转换为字符串类型,解决了关于index接受限制的警告。重点在于理解el-menu组件对index属性的字符串要求并提供解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:在使用vue开发项目时,用到了element-plus的组件el-menu,其中一直报这个warn
在这里插入图片描述
这是请求回来的数据。
在这里插入图片描述
一开始

  <el-sub-menu
      :index="item.id"
      v-for="(item, index) in menusList"
      :key="item.id"
  >
     <template #title>
        <el-icon>
          <!-- 通过这个方式引入icon图标组件 -->
          <component :is="iconList[index]"></component>
        </el-icon>
        <span>{{ item.authName }}</span>
      </template>
  </el-sub-menu>

修改后
将el-sub-menu的index改为字符串类型,就没有那个warn

  <el-sub-menu
      :index="item.id+''"
      v-for="(item, index) in menusList"
      :key="item.id"
  >
     <template #title>
        <el-icon>
          <!-- 通过这个方式引入icon图标组件 -->
          <component :is="iconList[index]"></component>
        </el-icon>
        <span>{{ item.authName }}</span>
      </template>
  </el-sub-menu>

总结原因
el-sub-menu的index属性只接受字符串类型。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值