wx:for循环出来的自定义组件,当数组数量改变时,新循环出来的组件的data不会重新初始化

小程序 文章 2021-03-05 13:41 471 0 全屏看文

AI助手支持GPT4.0

wx:for循环出来的自定义组件,当数组数量改变时,新循环出来的组件的data不会重新初始化The custom component out of the wx:for loop, when the number of arrays is changed, the data of the newly looped out component will not be reinitialized

wx:for循环出来的自定义组件,当数组数量改变时,新循环出来的组件的data不会重新初始化
框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx:for和自定义组件 工具 7.0.18 7.0.18.1740

具体如图


Framework type problem type API / component name terminal type wechat version basic library version applet bug Wx: for and custom component tool 7.0.18 7.0.18.1740, as shown in the figure

回答:

星光刀锋:

data中不要有函数,需要初始化在lifetimes生命周期函数中执行setData

跨商通:

是的。

改成在onLoad里this.setData吧。

昌💤:

问题出在wx.getStorageSync()上,比如:

this.setData{userInfo: wx.getStorageSync('userInfo')||{}})console.log(this.data.userInfo)

是没有内容的,需要先取值,如下

var userInfo = wx.getStorageSync('userInfo')||{}this.setData{userInfo: userInfo})console.log(this.data.userInfo)



-EOF-

AI助手支持GPT4.0