@blur校验数组重复
使用场景
table嵌套input
input失去焦点时判断输入的所有值是否有重复项,并对重复项增加01,02,03的后缀
实现效果
JS部分
data(){
return {
repeatTime:new Map([]) //记录每一项的重复次数
}
}
repeatZhName() {
// 重复字段的中文名后加_01
for (let i = 0; i < this.fieldInfoList.length - 1; i++) {
for (let j = i + 1; j < this.fieldInfoList.length; j++) {
if (this.fieldInfoList[i].cnName != '' && this.fieldInfoList[j].cnName != '') {
if (this.fieldInfoList[i].cnName === this.fieldInfoList[j].cnName) {
// return this.$message.warning('字段中文名存在重复')
if (this.repeatTime.get(this.fieldInfoList[j].cnName) !== undefined) {
let num = this.repeatTime.get(this.fieldInfoList[j].cnName)
this.repeatTime.set(this.fieldInfoList[i].cnName, ++num)
} else {
this.repeatTime.set(this.fieldInfoList[i].cnName, 1)
}
let num = this.repeatTime.get(this.fieldInfoList[i].cnName)
num = num > 9 ? num : '0' + num
this.fieldInfoList[j].cnName = this.fieldInfoList[j].cnName + '_' + num
}
}
}
}
}
HTML
<el-input
v-model="record.cnName"
:class="['text-input', { normal: pageType == 'check' }]"
placeholder="请输入"
:title="record.cnName"
:readonly="pageType == 'check'"
@blur="repeatZhName"
></el-input>