1. Use@cell-dblclick
Event, triggers event when double-clicked
<el-table @cell-dblclick="handleCellDblClick"
2. Cell settings
The main focus is to judge whether to switch the input box when double-clicking, then bind the ref, set the trigger point method when the focus is lost, and press the enter key to trigger point method.
<el-table-column prop="name" label="Name" width="180"> <template slot-scope="scope"> <span v-if="editableData !== ">{{ }}</span> <el-input v-else :ref="'input-' + scope.$index" v-model="" @blur="handleInputBlur()" @="handleInputEnter()" ></el-input> </template> </el-table-column>
3. Add the currently edited data
editableData: null, // The currently edited data item
4. Give logic to all methods
// Triggered when double-clickedhandleCellDblClick(row, column, cell, event) { if ( === 'customerBoxNum') { = row; // Set the currently edited data item this.$nextTick(() => { const inputRef = 'input-' + (row); const inputElement = this.$refs[inputRef]; if (inputElement) { (); // Focus input box } else { ('Input element not found:', inputRef); } }); } }, handleInputBlur(row) { // Save changes when the input box loses focus = null; // Return to static display status}, handleInputEnter(row) { // Save changes when pressing Enter = null; // Return to static display status},
5. Finish the work
This is the article about the method of double-clicking the VueElementUI table to edit a certain content. For more related Vue ElementUI table to modify the content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!