Vue?ElementUI?table實現(xiàn)雙擊修改編輯某個內(nèi)容的方法
1、使用@cell-dblclick
事件,當雙擊時觸發(fā)事件
<el-table @cell-dblclick="handleCellDblClick"
2、單元格設(shè)置
主要重點為判斷雙擊時切換input框,然后綁定ref,設(shè)置失去焦點時觸發(fā)點方法,與按enter鍵觸發(fā)點方法
<el-table-column prop="name" label="姓名" width="180"> <template slot-scope="scope"> <span v-if="editableData !== scope.row">{{ scope.row.name }}</span> <el-input v-else :ref="'input-' + scope.$index" v-model="scope.row.name" @blur="handleInputBlur(scope.row)" @keyup.enter.native="handleInputEnter(scope.row)" ></el-input> </template> </el-table-column>
3、添加當前編輯的數(shù)據(jù)
editableData: null, // 當前編輯的數(shù)據(jù)項
4、為所有的方法賦予邏輯
// 雙擊時觸發(fā) handleCellDblClick(row, column, cell, event) { if (column.property === 'customerBoxNum') { this.editableData = row; // 設(shè)置當前編輯的數(shù)據(jù)項 this.$nextTick(() => { const inputRef = 'input-' + this.boxList.indexOf(row); const inputElement = this.$refs[inputRef]; if (inputElement) { inputElement.focus(); // 聚焦輸入框 } else { console.error('Input element not found:', inputRef); } }); } }, handleInputBlur(row) { // 輸入框失去焦點時保存更改 this.editableData = null; // 返回到靜態(tài)顯示狀態(tài) }, handleInputEnter(row) { // 按下回車鍵時保存更改 this.editableData = null; // 返回到靜態(tài)顯示狀態(tài) },
5、打完收工
到此這篇關(guān)于VueElementUI table實現(xiàn)雙擊修改編輯某個內(nèi)容的方法的文章就介紹到這了,更多相關(guān)Vue ElementUI table雙擊修改內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Ant Design Vue table組件如何自定義分頁器
這篇文章主要介紹了Ant Design Vue table組件如何自定義分頁器問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04vue-tree-chart樹形組件的實現(xiàn)(含鼠標右擊事件)
Vue-Tree-Chart,一個Vue.js2組件,本文就詳細的介紹一下vue-tree-chart樹形組件的實現(xiàn)(含鼠標右擊事件),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02vue@cli3項目模板怎么使用public目錄下的靜態(tài)文件
這篇文章主要介紹了vue@cli3項目模板怎么使用public目錄下的靜態(tài)文件,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07