使用vue提供的表格,内部嵌套表单,表单可以输入内容,对表单进行校验,如果有一项填写,另一项提示必填,如果俩项都没填写,则不提示。
具体效果如下图所示:
具体的代码如下:
<template>
<div class="hello">
<el-form :model="form1" :rules="rules" ref="form1">
<el-table :data="form1.tableData" border>
<el-table-column prop="date" label="日期" width="180">
</el-table-column>
<el-table-column prop="name" label="姓名" width="180">
</el-table-column>
<el-table-column prop="address" label="地址" width="180">
</el-table-column>
<el-table-column prop="one" label="金额1" width="180">
<template slot-scope="scope">
<el-form-item :prop="'tableData.' + scope.$index + '.one'" :rules="scope.row.two ? [{required: true, message: '请输入金额1', trigger: 'blur'}]:[{required:false}]">
<el-input v-model="scope.row.one" clearable placeholder="请输入金额1"></el-input>
</el-form-item>
</template>
</el-table-column>
<el-table-column prop="two" label="金额2" width="180">
<template slot-scope="scope">
<el-form-item :prop="'tableData.' + scope.$index + '.two'" :rules="scope.row.one ? [{required: true, message: '请输入金额2', trigger: 'blur'}]:[{required:false}]">
<el-input v-model="scope.row.two" clearable placeholder="请输入金额2"></el-input>
</el-form-item>
</template>
</el-table-column>
</el-table>
</el-form>
</div>
</template>
data里边的数据项和之前的校验一样。没有什么大的改动