1.异步设置data里面的值
方法:
setDataAsync(opt) {
return new Promise(resolve => {
this.setData(opt, resolve)
})
}
调用:
async onShow() {
my.showLoading();
try {
const data = await apis.xxx();
await this.setDataAsync({
basicData: data,
pageShow: true
})
apis.xxx();
} catch (e) {
2.设置data里面的值中的key
data: {
subData: {}
}
let infoList = ['address1','address2','address3']
for (var i in infoList) {
this.setData({
[`subData[${infoList[i]}]`]: '',
})
}
网友评论