ElementPlus table 中嵌套 input 输入框
2023-12-13 17:30:01
需求
vue3 项目中 使用UI组件库 ElementPlus 时,table 中嵌入 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>
文章来源:https://blog.csdn.net/qq_53810245/article/details/134827099
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!