Vue3+ElementPlus编辑表格数据(指定行变为input)
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
点击编辑,使当前行需要修改的列变为 input
输入框
<template>
<div class="p-10">
<el-table :data="tableData" border>
<el-table-column prop="date" label="Date"></el-table-column>
<el-table-column prop="name" label="Name"></el-table-column>
<el-table-column prop="address" label="Address"></el-table-column>
<el-table-column label="Value">
<template #default="scope">
<span v-show="scope.$index !== editIndex">{{ scope.row.value }}</span>
<el-input
v-show="scope.$index === editIndex"
v-model="scope.row.value"
></el-input>
</template>
</el-table-column>
<el-table-column label="Operate">
<template #default="{ row }">
<el-button link @click="handleEdit(row)">Edit</el-button>
<el-button type="primary" link @click="handleSave">Save</el-button>
<el-button type="danger" link @click="handleDelete(row)"
>Delete</el-button
>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const tableData = ref([
{
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
value: '1'
},
{
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
value: '2'
},
{
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
value: '3'
},
{
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles',
value: '4'
}
])
const editIndex = ref(-1)
const handleEdit = (row) => {
editIndex.value = tableData.value.indexOf(row)
}
const handleSave = () => {
editIndex.value = -1
console.log(tableData.value)
}
const handleDelete = (row) => {
tableData.value.splice(tableData.value.indexOf(row), 1)
}
</script>
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献3条内容
所有评论(0)