問題
vue+element 列表
后台數據更新了,console.log 打印出來是更新的
但列表前端視圖未改變
解決
this.$set(this.data,key,value)
set函數接收三個參數分別為 target、key、val,其中target的值為數組或者對象,這正好和官網給出的調用Vue.set()方法時傳入的參數參數對應上。
Vue.set(target,propertyName/index,value)
this.$set(target,propertyName/index,value)
參數:
{Object | Array} target
{string | number} propertyName/index
{any} value
返回值:設置的值。
用法:
向響應式對象中添加一個 property,並確保這個新 property 同樣是響應式的,且觸發視圖更新。它必須用於向響應式對象上添加新 property,因為 Vue 無法探測普通的新增 property (比如 this.myObject.newProperty = 'hi')