解決vue數(shù)據(jù)更新但table內(nèi)容不更新的問題
場景:
table組件綁定的數(shù)據(jù)變化時,頁面沒有重新渲染,常見于子組件中使用table組件
原理:
創(chuàng)建實例時 數(shù)組在vue中沒有被監(jiān)聽到,屬于非響應式數(shù)據(jù),數(shù)組的下標變化無法監(jiān)聽到
解決方式:
<el-table
:key="tamptime"
stripe
border
fit
height="450"
:data="tabledata"
style="width: 100%"
>
<el-table-column
v-for="i in pretabledatacolumn"
:key="i.index"
show-overflow-tooltip
:prop="i"
:label="i"
width="230"
/>
</el-table>
data(){
return {
tabledata:[],
pretabledatacolumn:[],
tamptime:new Date().valueOf()
}
}
methods:{
changeTableData(){
this.tabledata = []
}
}1、利用vue中重寫的數(shù)組方法
splice,split,concat…
changeTableData(){
this.tabledata.splice(1,0)
}2、為table綁定一個key,數(shù)據(jù)變化時更改key值,或者使用v-if綁定一個不重復的值觸發(fā)組件渲染
changeTableData(){
this.tamptime = new Date().valueOf()
this.tabledata = newtabledata
}3、使用$set()
changeTableData(){
this.$set(tabledata,1,'newvalue')
}到此這篇關于解決vue數(shù)據(jù)更新但table內(nèi)容不更新的問題的文章就介紹到這了,更多相關vue數(shù)據(jù)更新table內(nèi)容不更新內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue通過moment插件實現(xiàn)獲取當前月的第一天和最后一天
這篇文章主要介紹了Vue 結(jié)合插件moment 實現(xiàn)獲取當前月的第一天和最后一天,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-10-10
element的el-form-item的prop作用小結(jié)
Vue表單驗證中的prop屬性用于指定需要驗證的表單字段,它定義了字段名稱并與驗證規(guī)則關聯(lián),確保數(shù)據(jù)的完整性和準確性,本文就來介紹一下element的el-form-item的prop作用,感興趣的可以了解一下2025-01-01

