vue循环遍历多个input,点击其中一个,当前边框样式改变为红色,在点另一个,其边框也变为红色(有两个input边框为红色,其他为灰色)。现在我点击一个,全部变红,请问有好的解决方案吗?
<div v-for="(item, index) in inputLeng" :key="index">
<input :placeholder="'点击' + item.str" style="margin-top: 10px" :class="{ 'borderColor': item.str }" @click="changeColor(index)" />
</div>
created() {
this.inputLeng = Array(10).fill({'str': false})
}
methods: {
changeColor(item) {
this.inputLeng[item].str = true
}
}
现在的情况
.fill()对象的话,所有对象都是指向同一个地址的。改一个动全部。
所以@click没问题,是测试用例没写好。