vue+element-ui el-table组件内表单验证问题

添加rules
rules: {
    variable_name: [{ required: true, message: '名称不能为空', trigger: "blur" }]
}
复制代码
html代码
<el-form ref="variableForm" :model="variable">
    <el-table :data="variable.Variable">
        <el-table-column label="名称">
            <template slot-scope="scope">
                <el-form-item :prop="'Variable.' + scope.$index + '.Name'" :rules='rules.variable_name'>
                    <el-input v-model.trim="scope.row.Name"></el-input>
                </el-form-item>
            </template>
        </el-table-column>
    </el-table>
<el-form>
复制代码
js代码
this.$refs.variableForm.validate(variable => {
    if (!variable) {
        return;
    }
}    
复制代码

关键:

如何给el-form-item动态绑定prop

:prop="'Variable.' + scope.$index + '.字段名'"

转载于:https://juejin.im/post/5bee563ee51d452e85192801

Logo

前往低代码交流专区

更多推荐