element-ui 的 el-table,点击单元格可编辑
<template> <div id="ailse_box"> <div> <el-table style="width: 100%;" :row-key="get_row_key" @cell-click="cell_click" :row-class-name="table_row_class_name" :data="tableData > <el-table-column type="selection" align="center" :reserve-selection="true"> </el-table-column> <el-table-column label="通道ID" align="center"> <template slot-scope="scope"> <div class="cell_btn" v-if="scope.row.index === cell_click_index && cell_click_label === '通道ID'" > <el-input size="mini" maxlength="300" placeholder="请输入通道ID" v-model="scope.row.taskid" /> <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="determine_modify(scope.row)" ></el-button> <el-button type="warning" size="mini" icon="el-icon-close" circle @click="cancel('cancel_edit')" ></el-button> </div> <span v-else>{{ scope.row.taskid }}</span> </template> </el-table-column> <el-table-column align="center" label="通道名称"> <template slot-scope="scope"> <div class="cell_btn" v-if="scope.row.index === cell_click_index && cell_click_label === '通道名称'" > <el-input size="mini" maxlength="300" placeholder="请输入通道名称" v-model="scope.row.taskname" /> <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="determine_modify(scope.row)" ></el-button> <el-button type="warning" size="mini" icon="el-icon-close" circle @click="cancel('cancel_edit')" ></el-button> </div> <span v-else>{{ scope.row.taskname }}</span> </template> </el-table-column> <el-table-column align="center" label="分析地址"> <template slot-scope="scope"> <div class="cell_btn" v-if="scope.row.index === cell_click_index && cell_click_label === '分析地址'" > <el-input size="mini" maxlength="300" placeholder="请输入分析地址" v-model="scope.row.address" /> <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="determine_modify(scope.row)" ></el-button> <el-button type="warning" size="mini" icon="el-icon-close" circle @click="cancel('cancel_edit')" ></el-button> </div> <span v-else>{{ scope.row.address }}</span> </template> </el-table-column> <el-table-column align="center" label="序号"> <template slot-scope="scope"> <div class="cell_btn" v-if="scope.row.index === cell_click_index && cell_click_label === '序号'" > <el-input size="mini" maxlength="300" placeholder="请输入序号" v-model="scope.row.no" /> <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="determine_modify(scope.row)" ></el-button> <el-button type="warning" size="mini" icon="el-icon-close" circle @click="cancel('cancel_edit')" ></el-button> </div> <span v-else>{{ scope.row.no }}</span> </template> </el-table-column> </el-table> </div> </div> </template> <script> export default { data() { return { tableData: [], // 表格数据 cell_click_index: null, // 点击的单元格 cell_click_label: '', // 当前点击的列名 } }, methods: { // 把每一行的索引放进row table_row_class_name({ row, rowIndex }) { row.index = rowIndex }, // 单元格点击事件 cell_click(row, column, cell, event) { this.cell_click_index = row.index this.cell_click_label = column.label switch (column.label) { case 'taskid': this.cell_click_index = row.index this.cell_click_label = column.label break case 'taskname': this.cell_click_index = row.index this.cell_click_label = column.label break default: return } }, // 确定修改 determine_modify(row) { console.log(row) }, }, // 点击取消 cancel(status) { switch (status) { case 'cancel_edit': this.cell_click_index = null this.cell_click_label = '' break default: break } }, } </script>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
2020-08-13 JS监听浏览器宽高