vue3+element Plus实现表单项的动态新增与删除
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
- HTML 关键代码
<div class="mb-6">
<div class="flex gap-6 align-items-center mb-6">
<span>接口头部信息</span>
<el-button :icon="Plus" circle class="ml-3" @click="addHeaderRow" />
</div>
<div class="flex gap-6 mb-3 header-wrap" v-for="(item, index) in state.editForm.header" :key="index">
<el-form-item prop="key">
<el-input v-model="item.key" placeholder="key"></el-input>
</el-form-item>
<el-form-item prop="value">
<el-input v-model="item.value" placeholder="value"></el-input>
</el-form-item>
<el-button :icon="Close" circle @click="deleteHeaderRow(index)" />
</div>
</div>
- TS 关键代码
const state = reactive({
editForm: {
...
header: [],
},
})
// 点击加号:添加一行header
const addHeaderRow = () => {
state.editForm.header.push({ key: '', value: '' });
};
// 点击减号:删除一行header
const deleteHeaderRow = (index: number) => {
state.editForm.header.splice(index, 1);
};
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 个月前
更多推荐
已为社区贡献9条内容
所有评论(0)