我对武伊林有意见。每次按下图片中的框时,都会向数组发送一个对象。可以选择所有的框。
条件是必须选择最多3个框,如果超过3个,我不想发送表单。
下面是按下任何框时运行的代码。
valueSelected(value,index) {
// console.log(index)
// console.log(value)
const i = this.mySelectedValue.indexOf(value)
// console.log('const i',i)
if (i === -1) {
this.mySelectedValue.push(value)
} else {
this.mySelectedValue.splice(i, 1)
}
const findIndex = this.user.positions.findIndex(v => {
return v.position === value.position
})
if (findIndex === -1) {
this.user.positions.push(value)
} else {
this.user.positions.splice(findIndex, 1)
}
},发布于 2022-11-29 10:02:47
考虑到这就是你所调用的全部功能。您可以在它周围放置一个if,所以如果已经选择了3个选项,那么它将不会触发。我认为这是一条简单的出路。
valueSelected(value,index) {
// console.log(index)
// console.log(value)
const i = this.mySelectedValue.indexOf(value)
// console.log('const i',i)
if (i === -1) {
if(this.mySelectedValue.length < 3){
this.mySelectedValue.push(value)
}
} else {
this.mySelectedValue.splice(i, 1)
}
const findIndex = this.user.positions.findIndex(v => {
return v.position === value.position
})
if (findIndex === -1) {
if(this.user.positions.length < 3){
this.user.positions.push(value)
}
} else {
this.user.positions.splice(findIndex, 1)
}
},https://stackoverflow.com/questions/74612145
复制相似问题