Vue 響應式刪除 Vue.delete( target, propertyName/index )


官方語法:

Vue.delete( target, propertyName/index )

  • 參數:

    • {Object | Array} target
    • {string | number} propertyName/index

    僅在 2.2.0+ 版本中支持 Array + index 用法。

  • 用法:

    刪除對象的 property。如果對象是響應式的,確保刪除能觸發更新視圖。這個方法主要用於避開 Vue 不能檢測到 property 被刪除的限制,但是你應該很少會使用它。

    在 2.2.0+ 中同樣支持在數組上工作。

    目標對象不能是一個 Vue 實例或 Vue 實例的根數據對象。

  • 實際開發用到的例子
  • 刪除對象的屬性: this.$delete(this.obj, '屬性值');
    刪除數組: this.$delete(this.obj.seaSurchargeFeeList, 下標);


  • 原生JS 刪除對象的屬性 :delete this.obj.seaFreightFeeList

  • 如果以上方法都不行就用下面的
  • //原生js刪除數組(開始刪除數組的下標,要刪除的個數)
    this.billformatsList.splice(index,1);//vue 提供的方法在這里不支持


免責聲明!

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



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