data() {
return {
list: [
{
name: '小明',
age: 18
},
{
name: '小美',
age: 12
}
],
text: '我是未修改的字符串值'
}
}
methods: {
changeFun(){
// 修改列表中小美的所有数据
this.$set(this.list, 1, {
name: '小美',
age: 18
})
// 修改列表中小美的年龄为18岁
this.$set(this.list[1], 'age', 18)
// 修改某个字符串属性
this.$set(this, 'text', '我是修改后的字符串值')
// 如果还不生效 加上 this.$forceUpdate(); 强制更新
this.$forceUpdate();
}
}
uniapp vue 数据更新 视图不更新 处理方法 this.$set(); this.$forceUpdate();刷新
于 2024-04-12 11:48:58 首次发布