vue表单点击按钮新增表单输入框(可扩展所有表单类型)
实现如下:
<el-form-itemv-for="(domain, index) in ruleForm.domains"
:label="index === 0 ? '解析服务域名:':''"
:key="domain.key"
:prop="'domains.' + index + '.value'"
:rules="{
required: true, message: '请输入服务域名', trigger: 'blur'
}"
>
<el-input v-model="domain.value" size="mini" style="width: 60%;"></el-input>
<el-button size="mini" @click.prevent="removeDomain(domain)">删除</el-button>
</el-form-item>
//数据格式this.ruleForm = {
gateway: '',
exit: '',
domains: [{
value: '',
key: 1
}],
}
//增加一行
addDomain() {
this.ruleForm.domains.push({
value: '',
key: Date.now()
});
},
//删除removeDomain(item) {
var index = this.ruleForm.domains.indexOf(item)
if (index !== -1) {
this.ruleForm.domains.splice(index, 1)
}
},
以上是 vue表单点击按钮新增表单输入框(可扩展所有表单类型) 的全部内容, 来源链接: utcz.com/z/377019.html