VUE關於data對象中數組修改和對象添加屬性的響應式問題


數組:

根據VUE官網:

 

 

數組修改:

  修改數組某個元素的值:

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

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

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

   修改數組的長度:vm.items.splice(newLength);

 

對象:

  給數組新添加響應式屬性:

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

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

  同時添加多個屬性:

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM