element-ui Form表单验证之对象属性验证

情况一:数组中对象属性验证

通过下标找到对象属性
<el-form-item label="主要业绩" prop="performanceList">
	<el-table :data="dataForm.performanceList" border style="width: 100%">
		<el-table-column prop="name" label="工程名称">
			<template #default="scope">
				<el-form-item :prop="'performanceList.' + scope.$index + '.name'"
                    :rules="[{ required: true, message: '请输入', trigger: 'blur' }]">
                	<el-input v-model="scope.row.name">el-input>
                el-form-item>
            template>
        el-table-column>
el-table>

情况二:多层对象验证

1、prop=“user.name” 2、rules验证里"user.name"
const dataForm: any = reactive({
    user: {
        name: '',
    }
});
const rules = reactive({
    "user.name": [
        { required: true, message: '请上传', trigger: 'change' },
    ],
});
<el-form-item label="姓名" prop="user.name">
	<el-input v-model="dataForm.user.name">el-input>
el-form-item>

你可能感兴趣的:(Element,vue.js,前端,javascript)