<template>
    <div>
        <el-form :model="info" ref="forms">
            <el-table
            ref="tableRef"
            :data="info.data"
            @row-click="rowClickHandle"
            border>
            <el-table-column align="center" property="name" label="*姓名">
                <template #default="row">
                    <el-form-item :prop="'data.' + row.$index + '.name'" :rules="formRules.name">
                        <el-input placeholder="请输入姓名" v-model="info.data[row.$index].name" />
                    </el-form-item>
                </template>
            </el-table-column>
            </el-table>
        </el-form>
        <el-form :model="info2" ref="forms2">
            <el-table
            ref="tableRef2"
            :data="info2.data"
            @row-click="rowClickHandle"
            border>
            <el-table-column align="center" property="role" label="角色">
                <template #default="row">
                    <el-form-item :prop="'data.' + row.$index + '.role'" :rules="formRules2.role">
                        <el-input placeholder="请输角色2" v-model="info2.data[row.$index].role" />
                    </el-form-item>
                </template>
            </el-table-column>
            </el-table>
        </el-form>
      <el-button type="primary" @click="submitForm()">Submit</el-button>
    </div>
</template>
<script setup lang="ts">
import {ref, reactive} from 'vue'
import type { FormInstance } from 'element-plus'
let info:any = reactive({
    data:[
        {
        name:''
        },
        {
            name:'2'
        }
    ]
})
let info2:any = reactive({
    data:[
        {
        role: '',
        },
        {
            role:'管理员'
        }
    ]
})
const formRules = reactive({
  name: [{ required: true, message: '请输入姓名', trigger: 'change' }],
  role: [{ required: true, message: '请选择', trigger: 'blur' }]
})
const formRules2 = reactive({
  name: [{ required: true, message: '请输入姓名', trigger: 'change' }],
  role: [{ required: true, message: '请选择', trigger: 'blur' }]
})
const forms = ref<FormInstance>()
const forms2 = ref<FormInstance>()
const submitForm = async () => {
    const refBasicForm = async () => {
        if (!forms) return
        return await forms.value?.validate((valid: any,fields) => {
            if (valid) {
            console.log('submit!')
            } else {
            console.log('error submit!',fields)
            return false
            }
        })
    }
    const refBasicForm2 = async () => {
        if (!forms2) return
        return await forms2.value?.validate((valid: any,fields) => {
            if (valid) {
            console.log('submit!')
            } else {
            console.log('error submit!',fields)
            return false
            }
        })
    }
    const formRes = await Promise.all([
        refBasicForm(),
        refBasicForm2(),
  ])
  if (formRes[0] == true && formRes[1] == true) {
    console.log('校验通过')
  } else {
    console.log('校验错误')
    return
  }  
}
</script>

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 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐