diff --git a/src/App.vue b/src/App.vue
index 317647b..88dae45 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -3,6 +3,7 @@
Form Demo 1: 基本使用
Form Demo 2: 行内表单
Form Demo 3: 表单验证
+ Form Demo 4: 动态表单
diff --git a/src/router/index.js b/src/router/index.js
index a5bec65..2ed1716 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -5,6 +5,7 @@ import {createRouter, createWebHistory} from 'vue-router'
const formDemo1 = () => import('../views/Form_Demo1.vue')
const formDemo2 = () => import('../views/Form_Demo2.vue')
const formDemo3 = () => import('../views/Form_Demo3.vue')
+const formDemo4 = () => import('../views/Form_Demo4.vue')
// 引入组件
@@ -27,6 +28,11 @@ const routes = [
name: 'form3',
component: formDemo3
},
+ {
+ path: '/form4',
+ name: 'form4',
+ component: formDemo4
+ },
]
// 创建路由器,使用createRouter方法,传入history(路由类型)和 创建好的路由routes
diff --git a/src/views/Form_Demo4.vue b/src/views/Form_Demo4.vue
index 3a45520..4f73216 100644
--- a/src/views/Form_Demo4.vue
+++ b/src/views/Form_Demo4.vue
@@ -7,13 +7,13 @@
- 新增域名
+ 新增域名
- 删除
+ 删除
-
+
+ 提交
+ 重置
+
@@ -39,7 +42,40 @@ export default {
domains: [
{value: ""}
]
+ },
+ rules: {
+ email:[
+ {required: true, message:'请填写邮箱地址!', trigger:'blur'},
+ {type: 'email', message: '请输入正确的邮箱格式', trigger: ['blur', 'change']}
+ ]
+ }
+ }
+ },
+ methods: {
+ submitForm(formName) {
+ this.$refs[formName].validate((valid) => {
+ if (valid) {
+ alert("提交成功!")
+ } else {
+ console.log('提交失败')
+ return false
+ }
+ })
+ },
+ addDomain() {
+ this.dynamicValidateForm.domains.push({
+ name: "",
+ key: Date.now(),
+ })
+ },
+ removeDomain(item) {
+ let index = this.dynamicValidateForm.domains.indexOf(item);
+ if (index !== -1) {
+ this.dynamicValidateForm.domains.splice(index, 1);
}
+ },
+ resetForm(formName) {
+ this.refs[formName].resetFields();
}
}
}
@@ -47,5 +83,19 @@ export default {