UP scFormTable 1.3 增加外部新增删除方法

This commit is contained in:
sc 2023-02-17 10:43:41 +08:00
parent 1c8869c476
commit c31958d0b7
2 changed files with 29 additions and 3 deletions

View File

@ -1,10 +1,10 @@
<!--
* @Descripttion: 表单表格
* @version: 1.2
* @version: 1.3
* @Author: sakuya
* @Date: 2023年2月9日12:32:26
* @LastEditors: sakuya
* @LastEditTime: 2023年2月17日09:52:24
* @LastEditTime: 2023年2月17日10:41:47
-->
<template>
@ -98,6 +98,15 @@
},
rowDel(row, index){
this.data.splice(index, 1)
},
//
pushRow(row){
const temp = row || JSON.parse(JSON.stringify(this.addTemplate))
this.data.push(temp)
},
//index
deleteRow(index){
this.data.splice(index, 1)
}
}
}

View File

@ -8,7 +8,7 @@
<el-input v-model="form.title"></el-input>
</el-form-item>
<el-form-item label="表格" prop="list">
<sc-form-table v-model="form.list" :addTemplate="addTemplate" drag-sort placeholder="暂无数据">
<sc-form-table ref="table" v-model="form.list" :addTemplate="addTemplate" drag-sort placeholder="暂无数据">
<el-table-column prop="time" label="时间" width="180">
<template #default="scope">
<el-time-select v-model="scope.row.time"></el-time-select>
@ -44,6 +44,10 @@
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" header="方法" style="margin-top: 15px;">
<el-button type="primary" @click="pushRow">外部插入行</el-button>
<el-button type="primary" @click="deleteRow">外部删除第一行</el-button>
</el-card>
</el-main>
</template>
@ -108,6 +112,19 @@
},
resetForm(){
this.$refs.ruleForm.resetFields();
},
pushRow(){
const data = {
time: '18:00',
type: '1',
val: '0',
open: true,
checked: true
}
this.$refs.table.pushRow(data)
},
deleteRow(){
this.$refs.table.deleteRow(0)
}
}
}