vue3点击表格某个单元格文本就切换成输入框,其他单元格不变化

html 复制代码
<el-table :data="data.tableData" height="60vh" border scrollbar-aways-on>
        <el-table-column label="序号" type="index" width="80" fixed />
        <el-table-column label="操作" width="120" fixed>
            <template #default="{ row }">
                <el-button type="danger" text @click="deleteBtn(row)" :disabled="row.status">删除</el-button>
                <el-button style="color: #3592FF" text @click="enableBtn(row)">{{ row.status ? '停用' : '启用' }}</el-button>
            </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" width="120" />
        <el-table-column prop="phone" label="手机号" />
        <el-table-column prop="kanno" label="操作人" />
        <el-table-column prop="kanno" label="操作时间" />
        <el-table-column prop="kanno" label="创建人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="姓名">
            <template #default="scope">
                <template v-if="scope.cellIndex == cellIndex && scope.$index == index">
                    <el-input v-model="scope.row.status" @blur="saveCell" />
                </template>
                <template v-else>
                    <div @click="editCell(scope, scope.$index)">{{ scope.row.status }}</div>
                </template>
            </template>
        </el-table-column>
    </el-table>
javascript 复制代码
const cellIndex = ref('')
const index = ref('')

function editCell(row, ind) {
    cellIndex.value = row.cellIndex
    index.value = ind
}
function saveCell() {
    cellIndex.value = ''
    index.value = ''
}

效果如下

点击第一行的文本

点击第二行文本

相关推荐
Cacciatore->16 分钟前
Electron 快速上手
javascript·arcgis·electron
vvilkim23 分钟前
Electron 进程间通信(IPC)深度优化指南
前端·javascript·electron
某公司摸鱼前端1 小时前
ES13(ES2022)新特性整理
javascript·ecmascript·es13
清幽竹客2 小时前
vue-30(理解 Nuxt.js 目录结构)
前端·javascript·vue.js
知性的小mahua2 小时前
echarts+vue实现中国地图板块渲染+省市区跳转渲染
vue.js
weiweiweb8882 小时前
cesium加载Draco几何压缩数据
前端·javascript·vue.js
我不吃饼干9 天前
鸽了六年的某大厂面试题:你会手写一个模板引擎吗?
前端·javascript·面试
我不吃饼干9 天前
鸽了六年的某大厂面试题:手写 Vue 模板编译(解析篇)
前端·javascript·面试
前端fighter9 天前
为什么需要dependencies 与 devDependencies
前端·javascript·面试
满楼、9 天前
el-cascader 设置可以手动输入也可以下拉选择
javascript·vue.js·elementui