element-UI el-table修改input值視圖不更新問題
更新時間:2024年02月29日 09:20:47 作者:代碼の搬運工
這篇文章主要介紹了element-UI el-table修改input值視圖不更新問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
問題
1.input框通過v-model=“scope.row.molecule”
綁定的值去修改,控制臺打印輸出的是正確修改的值。
但是視圖不跟新
<input class="inputs" type="text"v-model="scope.row.molecule">
2.通過監(jiān)聽@input事件去修改當(dāng)前行里面的數(shù)組數(shù)據(jù)
控制臺打印也是能正確輸出
但視圖還是不更新
<input @input="changeMolecule($event,scope.row)" class="inputs" type="text"
v-model="scope.row.molecule">
changeMolecule(event, row) {
row.molecule=event.target.value
},
3.通過監(jiān)聽@input事件去調(diào)用this.$set()改變數(shù)據(jù)
控制臺打印輸入也是正確輸出
視圖還是不更新
changeMolecule(data, index, row) {
this.topicList.forEach(item=>{
if(item.targetId===row.targetId){
this.$set(item,'molecule',row.molecule)
}
})
},
解決方法
還是通過this.$set(),但是不能直接去修改對象里的某一個值
因為el-table監(jiān)聽的是一整行數(shù)據(jù),并不是某一個單元格
所以需要重新賦值一整行數(shù)據(jù)
<el-table :data="topicList" border height="60vh" style="width: 100%">
<el-table-column label="指標(biāo)" prop="targetTitle" width="180"></el-table-column>
<el-table-column label="指標(biāo)計算方法" prop="computingMethod"></el-table-column>
<el-table-column label="分子/分母(自動計算)" width="300">
<template scope="scope">
<div class="input-div">
<input @input="changeMolecule(topicList,scope.$index,scope.row)" class="inputs" type="text"
v-model="scope.row.molecule">
<span class="divide">/</span>
<input @input="changeDenominator(topicList,scope.$index,scope.row)" class="inputs" type="text"
v-model="scope.row.denominator">
<span class="divide"
v-if="scope.row.molecule&&!isNaN(Number(scope.row.molecule))&& scope.row.denominator&&!isNaN(Number(scope.row.denominator))">
{{(scope.row.molecule/scope.row.denominator*100).toFixed(2)+'%'}}
</span>
</div>
</template>
</el-table-column>
</el-table>
changeMolecule(data, index, row) {
//兩種都可以
this.$set(data, index, row)
//this.$set(this.topicList,index,row)
},

總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Element-UI Table組件上添加列拖拽效果實現(xiàn)方法
這篇文章主要為大家詳細介紹了Element-UI Table組件上添加列拖拽效果的實現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04
ElementUI+命名視圖實現(xiàn)復(fù)雜頂部和左側(cè)導(dǎo)航欄
本文主要介紹了ElementUI+命名視圖實現(xiàn)復(fù)雜頂部和左側(cè)導(dǎo)航欄,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
關(guān)于vuepress部署出現(xiàn)樣式的問題及解決
這篇文章主要介紹了關(guān)于vuepress部署出現(xiàn)樣式的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
解決vue-cli@3.xx安裝不成功的問題及搭建ts-vue項目
這篇文章主要介紹了解決vue-cli@3.xx安裝不成功的問題及搭建ts-vue項目.文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02

