微信小程序uniapp中如何解决key失效的问题?

2026-04-01 16:012阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计215个文字,预计阅读时间需要1分钟。

微信小程序uniapp中如何解决key失效的问题?

使用uni-app的代码模板功能展示图片列表,以下为简化后的代码:

微信小程序uniapp中如何解决key失效的问题?

uniapp 代码

<template> <view> <image v-for="(item, i) in fileList" :key="item[urlKey]" :src="item[urlKey]"></image> </view> </template> <script> export default { props: { urlKey: {default: 'url'}, fileList: Array } } </script>

编译到 微信小程序

<view> <block wx:for="{{fileList}}" wx:for-item="item" wx:for-index="i" wx:key="urlKey"> <image src="{{item[urlKey]}}"></image> </block> </view>

貌似不支持 :key="item[urlKey]" 这种语法

解决方案:

<template> <view> <image v-for="(item, i) in fileList" :key="key(item)" :src="item[urlKey]"></image> </view> </template> <script> export default { props: { urlKey: {default: 'url'}, fileList: Array }, computed: { key() { return e => e[this.urlKey] } } } </script>

使用computed就可以解决了

到此这篇关于uniapp微信小程序:key失效的解决方法的文章就介绍到这了,更多相关uniapp小程序key失效内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

标签:解决方法

本文共计215个文字,预计阅读时间需要1分钟。

微信小程序uniapp中如何解决key失效的问题?

使用uni-app的代码模板功能展示图片列表,以下为简化后的代码:

微信小程序uniapp中如何解决key失效的问题?

uniapp 代码

<template> <view> <image v-for="(item, i) in fileList" :key="item[urlKey]" :src="item[urlKey]"></image> </view> </template> <script> export default { props: { urlKey: {default: 'url'}, fileList: Array } } </script>

编译到 微信小程序

<view> <block wx:for="{{fileList}}" wx:for-item="item" wx:for-index="i" wx:key="urlKey"> <image src="{{item[urlKey]}}"></image> </block> </view>

貌似不支持 :key="item[urlKey]" 这种语法

解决方案:

<template> <view> <image v-for="(item, i) in fileList" :key="key(item)" :src="item[urlKey]"></image> </view> </template> <script> export default { props: { urlKey: {default: 'url'}, fileList: Array }, computed: { key() { return e => e[this.urlKey] } } } </script>

使用computed就可以解决了

到此这篇关于uniapp微信小程序:key失效的解决方法的文章就介绍到这了,更多相关uniapp小程序key失效内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

标签:解决方法