点击后,我想将值从false更改为true。我找到了通过索引号执行相同操作的示例,但是没有索引可以吗?只是名字?
data() {
return {
names: [
{n: 'Dima', isClck: false},
{n: 'Roma', isClck: false},
{n: 'Masha', isClck: false},
],
}
},
methods :
{
MyClick(name)
{
// come code here
}
答案 0 :(得分:0)
```
MyClick(name)
{
let selected = this.names.filter(i => i.n === name)[0]
//or = this.names.find(i => i.n === name)
this.isClck = !this.isClck
}
```
答案 1 :(得分:0)
您应该可以在模板中完全执行此操作
<ul>
<li v-for="name in names">
<button @click="name.isClick = !name.isClick">{{name.n}}</button>
</li>
</ul>