vue2+element-ui新增編輯表格+刪除行功能
更新時間:2024年07月06日 10:49:11 作者:CiL#
這篇文章主要介紹了vue2+element-ui新增編輯表格+刪除行功能,本文通過示例代碼給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧
vue2+element-ui新增編輯表格+刪除行
實現(xiàn)效果:


代碼實現(xiàn) :
<el-table :data="dataForm.updateData"
border
:header-cell-style="{'text-align':'center'}"
:cell-style="{'text-align':'center'}">
<el-table-column label="選項字段"
align="center"
prop="name">
<template slot-scope="scope">
<el-form-item :prop="'updateData.' + scope.$index + '.formName'"
:rules="[
{ required: true, message: '請輸入', trigger: 'blur' },
{ min: 1, max: 20, message: '長度在1到 20個字符', trigger: 'blur' }
]">
<el-input v-model="scope.row.formName"
clearable></el-input>
</el-form-item>
</template>
</el-table-column>
<el-table-column fixed="right"
label="操作">
<template slot-scope="scope">
<el-button @click.native.prevent="addRow(scope.$index,scope.row,dataForm.updateData)"
type="text"
size="small">
新增
</el-button>
<el-button @click.native.prevent="deleteRow(scope.$index,scope.row,dataForm.updateData)"
type="text"
size="small"
v-if="dataForm.updateData.length!=1">
移除
</el-button>
</template>
</el-table-column>
</el-table>
<script>
export default {
data () {
return {
dataForm: {
// 自定義字段
updateData: [
{
// id: '',
formName: ''
}
]
// 其他...
}
}
},
methods: {
// addRow 新增 自定義字段表格行
addRow (index, rows, item) {
// console.log(index, rows, item)
// this.dataForm.updateData.push({
// // sort: this.dataForm.updateData && this.dataForm.updateData.length > 0 ? this.dataForm.updateData.length + 1 : 1,
// id: null,
// formName: ''
// })
// 數(shù)組中添加新元素
item.splice(index + 1, 0, { formName: '' })
},
// deleteRow 刪除 自定義字段表格行
deleteRow (index, rows, item) {
// console.log(index, '當前行索引', rows, '刪除的目標行')
// 從index這個位置開始刪除數(shù)組后的1個元素
item.splice(index, 1)
// this.$confirm('刪除當前行, 是否繼續(xù)?', '提示', {
// confirmButtonText: '確定',
// cancelButtonText: '取消',
// type: 'warning'
// }).then(() => {
// item.splice(index, 1)
// // this.delArrId.push(rows.id) // 被刪除的id數(shù)組集合
// // rows.isDelete = 1
// }).catch(() => {
// this.$message({
// type: 'info',
// message: '已取消刪除'
// })
// })
},
}
}
</script>補充:vue3+element-plus: el-table表格動態(tài)添加或刪除行
vue3+element-plus: el-table表格動態(tài)添加或刪除行
貼圖:

表格代碼:

添加代碼:

到此這篇關于vue2+element-ui新增編輯表格+刪除行的文章就介紹到這了,更多相關vue2 element-ui 新增表格內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue3項目+element-plus:時間選擇器格式化方式
這篇文章主要介紹了vue3項目+element-plus:時間選擇器格式化方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
vue3項目typescript如何export引入(imported)的interface問題
這篇文章主要介紹了vue3項目typescript如何export引入(imported)的interface問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06
vue實現(xiàn)動態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動畫
這篇文章主要介紹了vue實現(xiàn)動態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動畫方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
基于vue實現(xiàn)滾動條滾動到指定位置對應位置數(shù)字進行tween特效
這篇文章主要介紹了基于vue實現(xiàn)滾動條滾動到指定位置對應位置數(shù)字進行tween特效,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-04-04

