element动态表单验证一
<template>
<el-form :model="dynamicValidateForm" ref="dynamicValidateForm" label-width="100px" class="demo-dynamic bg-white pg-20" style="width: 30%;">
<el-form-item>
<el-button @click="addDomain" type="primary">新增域名</el-button>
</el-form-item>
<div class=""
v-for="(domain, index) in dynamicValidateForm.domains"
:key="index"
>
<el-form-item
prop="email"
label="邮箱"
:prop="'domains.' + index + '.email'"
:rules="[
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
]"
>
校验:{{'domains.' + index + '.value'}}
<el-input v-model="domain.email"></el-input>
</el-form-item>
<el-form-item
label="域名"
:prop="'domains.' + index + '.value'"
:rules="{
required: true, message: '域名不能为空', trigger: 'blur'
}"
>
校验:{{'domains.' + index + '.value'}}
<el-input v-model="domain.value"></el-input>
<el-button @click.prevent="removeDomain(domain)">删除</el-button>
</el-form-item>
</div>
<el-form-item>
<el-button type="primary" @click="submitForm('dynamicValidateForm')">提交</el-button>
<el-button @click="resetForm('dynamicValidateForm')">重置</el-button>
</el-form-item>
</el-form>
</template>
<script>
export default {
data() {
return {
skuList:[{
"goodsId": "29",
"skuId": "8",
"skuSn": "3333",
"bundleNumber": null,
"name": null,
"price": 1.00,
"stock": 2,
"quantity": 3,
"warehouseLocationNumber": null,
"lockedStock": null,
"weight": null,
"width": 2.00,
"thickness": 1.00,
"length": 3.00,
"picUrl": "https://oss.qiegang.com/banner/brands/20241129/4ea5f7ff2a2d4e9a966e6eff348892bd.jpg",
"warehouse": "切钢上海宝山仓",
"outboundFeels": null,
"skuIndate": null
}],
dynamicValidateForm: {
domains: [{
value: '',
email:""
}],
}
};
},
methods: {
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
removeDomain(item) {
var index = this.dynamicValidateForm.domains.indexOf(item)
if (index !== -1) {
this.dynamicValidateForm.domains.splice(index, 1)
}
},
addDomain() {
this.dynamicValidateForm.domains.push({
value: '',
email:""
});
}
}
}
</script>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-11-29 vue二次封装Element的table组件