From 8488465d2464bc2ec15a9827c36d8047f66013b2 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Fri, 13 Oct 2023 10:16:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E7=BB=84=E4=BB=B6=E7=9A=84=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 1 + src/router/index.js | 6 ++++ src/views/Form_Demo4.vue | 60 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 5 deletions(-) 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 {