赞
踩
划重点:
:prop="‘specificationsCopy.’+scope.$index+’.name’"
:rules=“rules.name”
如果:rules=“rules.name” 换成required就会报错xxx is required
<el-form-item label="商品规格:" required> <div class="table"> <el-table :data="ruleForm.specificationsCopy" row-key="skuId" border style="width: 100%" :header-cell-style="{ background: '#F7F7F7' }"> <el-table-column prop="date" label="商品规格" header-align="center"> <template slot="header"> <span>商品规格</span> </template> <template slot-scope="scope"> <el-form-item :prop="'specificationsCopy.'+scope.$index+'.name'" :rules="rules.name"> <el-input v-model="scope.row.name" :disabled="pageInfo.type==='check'" placeholder="请输入商品规格" /> </el-form-item> </template> </el-table-column> <el-table-column prop="name" label="规格值" header-align="center"> <template slot="header"> <span>规格值</span> </template> <template slot-scope="scope"> <el-form-item :prop="'specificationsCopy.'+ scope.$index +'.value'" :rules="rules.value"> <el-input v-model="scope.row.value" :disabled="pageInfo.type==='check'" placeholder="请输入规格值" /> </el-form-item> </template> </el-table-column> <el-table-column prop="address" label="操作" header-align="center" width="140" align="center"> <template slot-scope="scope"> <el-button type="text" class="danger" :disabled="pageInfo.type==='check'||ruleForm.specificationsCopy.length===1" @click="delSku(scope.$index)">删除</el-button> </template> </el-table-column> </el-table> <el-button style="margin-top:12px" type="primary" :disabled="pageInfo.type==='check'" @click="addSku">添加商品规格</el-button> </div> </el-form-item>
data定义格式
ruleForm: {
specificationsCopy: {
mainTitle: "",
name: "",
value: "",
}
},
定义规则
rules: {
mainTitle: [
{ required: true, message: '请输入主标题', trigger: 'blur' }
],
name: [
{ required: true, message: '请输入商品规格', trigger: 'blur' }
],
value: [
{ required: true, message: '请输入规格值', trigger: 'blur' }
],
},
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。