我想在用户点击按钮后更改图像的id
。最初,元素的id
应该是B0_h,但是在用户单击按钮后,数组中的值应该更改为true
。最初,所有数组值都是false
,但是一旦数组中元素的值变为true
,id
就应该变为B0_v。
使用Vue开发工具,我注意到数组中的值正在按预期更改,但是v-bind
无法检测到这种更改。从v-bind
的角度来看,B [0]
的值仍然是false
。因此,id
仍然是B0_h。
这是我的模板:
<template>
<div>
<button type="button" id="button0" v-on:click="toggle('B0')"></button>
<img src="../assets/img1.png" alt="A" v-bind:id="[A[0] === true ? 'A0_v' : 'A0_h']" >
<img src="../assets/img2.png" alt="B" v-bind:id="[B[0] === true ? 'B0_v' : 'B0_h']">
</div>
</template>
以下是我的脚本:
<script>
export default {
name: 'Demo',
props: {},
data: function(){
return{
A: [false,false,false,false,false,false,false,false,false],
B: [false,false,false,false,false,false,false,false,false],
playerTurn: true;
}
},
methods:
{
toggle(x)
{
if(x == 'B0' && this.playerTurn)
{
this.B[0] = true;
}
}
}
}
</script>
你知道我在这里做错了什么吗?