vue的set完成數據修改視圖不更新的問題處理


在vue的使用當中我們可能會遇到修改數據后vue視圖不更新的情況,這種情況常出現在:

使用下標修改數組或對象的值時:

調用方法:Vue.set( target, key, value )
target:要更改的數據源(可以是對象或者數組)
key:要更改的具體數據
value :重新賦的值

      enterprise: [{
        title: '',
        introduce: '',
        imgs: []
      }],

    
      //調換數組enterprise的兩組數據位置,更新視圖

      let enbefore = this.enterprise[index - 1];
      let enthis = this.enterprise[index];
      this.enterprise[index - 1] = this.enterprise[index];
      this.enterprise[index] = enbefore;
      this.$set(this.enterprise, index - 1, enthis);
      this.$set(this.enterprise, index, enbefore);

   

 


免責聲明!

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



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