今天在项目中碰到这样一个问题:

从父组件中传过来的props中的数据,在子组件中想加入一个变量。在created中加入变量,在方法中打印次变量是有的,但是当变量发生变化之后,视图中是响应不到的。

解决此种问题有两种方法:

一、直接操作props中的数据

在computed中写下:

computed:{
    newData:{
        if(this.oldData.list != undefined){
            this.oldData.list.map(item=>{
                this.$set(item,'isChecked','');
            })
        }
    }
}

在一个对象中添加一个新的属性

vm.$set(vm.userProfile, 'age', 27)

添加多个新属性

vm.userProfile = Object.assign({}, vm.userProfile, {
    age: 27,
    favoriteColor:'pink'
});

二、在更改新添加的属性的时候操作

toggleShow(item){
    item.isChecked = !item.isChecked;
    this.newData.list.reverse().reverse();
}

 

相关文章:

  • 2022-12-23
  • 2021-10-11
  • 2021-04-28
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2020-03-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2018-07-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案