Vue或uni-app框架中给data中的对象【obj、array】属性添加一个新的属性时会发生什么,如何解决?【在Vue-data中的对象直接添加属性,obj.a会无效,必须使用$set方法】
参考官方文档:https://cn.vuejs.org/v2/api/#Vue-set参考别人的解决方案:https://www.jianshu.com/p/8c3329bd0719自己的解决方案:【非常重要】这里不能直接this.personalList.setReferrer赋值,因为 Vue 无法探测普通的新增属性,必须使用$set方法...
·
参考官方文档:https://cn.vuejs.org/v2/api/#Vue-set
参考别人的解决方案:https://www.jianshu.com/p/8c3329bd0719
自己的解决方案:
【非常重要】这里不能直接this.personalList.setReferrer赋值,因为 Vue 无法探测普通的新增属性,必须使用$set方法
this.$set(this.personalList, "setReferrer", {
title: "设置推荐人",
showExtraIcon: true,
iconType: "iconicon-setting",
})
export default {
async onShow() {
// 仅当未设置推荐人的wallet才显示设置推荐人功能
if (!await ReferrerRelationNetwork.queryReferrerAddress()) {
// 【非常重要】这里不能直接this.personalList.setReferrer赋值,因为 Vue 无法探测普通的新增属性,必须使用$set方法
this.$set(this.personalList, "setReferrer", {
title: "设置推荐人",
showExtraIcon: true,
iconType: "iconicon-setting",
})
}
console.log(this.personalList)
},
data() {
return {
popupShowExport: false,
popupShowLogout: false,
popupShowSetReferrer: false,
username: this.$username,
// 垂直方向滑动的高度
scrollHeight: this.$windowHeight - 320 + "px",
// list的数据
personalList: {
setting: {
title: "系统设置",
showExtraIcon: true,
iconType: "iconicon-setting",
},
exportMnemonic: {
title: "导出助记词",
showExtraIcon: true,
iconType: "icondaochu",
},
agreement: {
title: "服务协议",
showExtraIcon: true,
iconType: "iconxieyizhihang",
},
community: {
title: "社区管理",
showExtraIcon: true,
iconType: "iconzhinengxuexipingtai",
},
logout: {
title: "注销账户",
showExtraIcon: true,
iconType: "iconziyuanxhdpi",
},
version: {
title: "版本更新",
showExtraIcon: true,
iconType: "iconbanbengengxin",
},
},
};
},
更多推荐
已为社区贡献42条内容
所有评论(0)