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)文章
uni-app中使用ECharts配置四種不同的圖表(示例詳解)
在uni-app中集成ECharts可以為我們的應(yīng)用提供強大的圖表功能,我們詳細說一下如何在uni-app中使用ECharts,并配置四種不同的圖表,感興趣的朋友跟隨小編一起看看吧2024-01-01
解決Vue-cli npm run build生產(chǎn)環(huán)境打包,本地不能打開的問題
今天小編就為大家分享一篇解決Vue-cli npm run build生產(chǎn)環(huán)境打包,本地不能打開的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
關(guān)于element-ui的隱藏組件el-scrollbar的使用
這篇文章主要介紹了關(guān)于element-ui的隱藏組件el-scrollbar的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05
vue實現(xiàn)前端excel導(dǎo)出的三種方法實現(xiàn)與對比總結(jié)
在Vue項目中實現(xiàn)前端Excel導(dǎo)出功能,主要有三種主流方案,各有特點,下面小編就為大家詳細介紹一下這三種方法的實現(xiàn),大家可以根據(jù)需要進行選擇2025-10-10
關(guān)于element-ui?select?下拉框位置錯亂問題解決
這篇文章主要介紹了關(guān)于element-ui?select?下拉框位置錯亂問題解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09

