VUE on a data object and change the array responsive objects adding attributes issues

Array:

According VUE official website:

 

 

Array Modified:

  Modify the value of an array element:

    Vue.set(this.items, indexOfItem, newValue);

    this.$set(this.items, indexOfItem, newValue);

    this.items.splice(indexOfItem, 1, newValue);

   Modifying the length of the array: vm.items.splice (newLength);

 

Object:

  Responsive to an array of newly added attributes:

    Vue.set(vm.userProfile, 'age', 27);

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

  While adding more properties:

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

 

Guess you like

Origin www.cnblogs.com/lianchenxi/p/11731311.html