赞
踩
):
<div v-for="(item, index) in form.labels" :key="index" class="label"> <el-form-item label="名称:" :prop="'labels.' + index + '.name'" :rules="{ required: true, message: '请输入', trigger: 'blur' }" class="middleInput"> <el-input v-model.trim="item.name" maxlength="30" placeholder="请输入"></el-input> <i class="el-icon-circle-plus-outline icon" v-if="(index === (form.labels.length - 1))" @click.prevent="addKey(item)"></i> <i class="el-icon-remove-outline icon" v-if="(form.labels.length > 1)" @click.prevent="removeKey(item, index)"></i> </el-form-item> <el-form-item label="值:" :prop="'labels.' + index + '.value'" :rules="{ required: true, message: '请输入', trigger: 'blur' }" class="middleInput"> <el-input maxlength="100" show-word-limit type="textarea" :rows="3" v-model.trim="item.value" placeholder="请输入"></el-input> </el-form-item> </div>
//data: form: { labels: [{ name: '', value: '' }] }, // methods: addKey (item) { this.form.labels.push({ name: '', value: '' }) }, removeKey (item, index) { this.form.labels.splice(index, 1) },
核心代码:
:prop="'labels.' + index + '.name'"
:rules="{
required: true, message: '请输入', trigger: 'blur'
}"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。