好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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失效内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://segmentfault测试数据/a/1190000039035350

查看更多关于uniapp微信小程序:key失效的解决方法的详细内容...

  阅读:50次