Vue如何動態(tài)修改el-table的某列數(shù)據(jù)
動態(tài)修改el-table的某列數(shù)據(jù)
1.對話框打開時調(diào)用函數(shù)open@opened="checked"
2.可編輯
<el-table-column ??? -------- visEdit="true" ??????>
3.同步選中的數(shù)據(jù)List:multipleSelection ,函數(shù) checked: function ()
設(shè)置el-table某一列點擊出現(xiàn)輸入框可以編輯
設(shè)置el-table 某一列點擊出現(xiàn)輸入框可以編輯,鼠標(biāo)失去輸入框焦點時輸入框消失,顯示對應(yīng)的值。
如下圖所示:
具體實現(xiàn):
<el-table :data="tableData" v-loading="loading" :row-class-name="tableRowClassName" border max-height="780" style="width: 100%" size="mini" @cell-click="tabClick"> <el-table-column label="順序" prop="adSort"> <template slot-scope="scope"> <span v-if="scope.row.index === tabClickIndex && tabClickLabel === '順序'"> <el-input v-model="scope.row.adSort" type="number" maxlength="20" placeholder="請輸入順序" size="mini" @blur="inputBlur(scope.row)" /> </span> <span v-else>{{ scope.row.adSort }}</span> </template> </el-table-column> </el-table>
通過 tableRowClassName 設(shè)置每一行的index:
tableRowClassName ({ row, rowIndex }) { // 把每一行的索引放進(jìn)row row.index = rowIndex }
行點擊事件,當(dāng)某一行被點擊時,該行的某列設(shè)置 tabClickIndex:
由于
v-if="scope.row.index === tabClickIndex && tabClickLabel === '順序'"
所以當(dāng)前點擊行的某列會出現(xiàn)輸入框:
// tabClick row 當(dāng)前行 column 當(dāng)前列 tabClick (row, column, cell, event) { switch (column.label) { case '順序': this.tabClickIndex = row.index this.tabClickLabel = column.label break default: return } console.log('tabClick', this.tabClickIndex, row.adName, row.adSort) }
鼠標(biāo)失焦事件:
// 失去焦點初始化 inputBlur (row) { // console.log('row', row) this.tabClickIndex = null this.tabClickLabel = '' }
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
- Vue如何設(shè)置el-table背景透明樣式
- vue2.0 + element UI 中 el-table 數(shù)據(jù)導(dǎo)出Excel的方法
- VUE2.0 ElementUI2.0表格el-table自適應(yīng)高度的實現(xiàn)方法
- vue實現(xiàn)動態(tài)控制el-table表格列的展示與隱藏
- vue+element獲取el-table某行的下標(biāo),根據(jù)下標(biāo)操作數(shù)組對象方式
- vue el-table實現(xiàn)自定義表頭
- Vue+element使用row-class-name修改el-table某一行解決背景色無效的方法
相關(guān)文章
vue3的watch用法以及和vue2中watch的區(qū)別
這篇文章主要介紹了vue3的watch用法以及和vue2中watch的區(qū)別,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04