uniapp - v-for key报错

报错如下:

VM6296:1 WXMLRT_$gwx:./pages/Home/home.wxml:block:1:21250: Now you can provide attr wx:key for a wx:for to improve performance.

错误代码:

<view v-for="tag in item.tabs" :key="'nav'+tag.id" class="display-inline-block" :data-iindex="item.index" :data-id="tag.id" @tap="setZhibo">
      <view :style="tag.status=='close' ?'display:none':''" :class="{'tag-item':true,'tag-active':tag.id ==item.zhiboName}">{{tag.name}}</view>
</view>

问题:
key值绑定了。但是非 h5 平台 :key 不支持表达式 item.index+tag.id,详情参考:https://uniapp.dcloud.io/use?id=key

所以,重写key值

<view v-for="tag in item.tabs" :key="tag.id" class="display-inline-block" :data-iindex="item.index" :data-id="tag.id" @tap="setZhibo">
      <view :style="tag.status=='close' ?'display:none':''" :class="{'tag-item':true,'tag-active':tag.id ==item.zhiboName}">{{tag.name}}</view>
</view>

解决

posted @ 2020-09-02 14:03  gggggggxin  阅读(1571)  评论(0编辑  收藏  举报