代码如下
Vuejs demo
{{ isread }}
var demo = new Vue({
el: '#demo',
data: {
posts: ['This is a post', 'another post', 'last post'],
isread: false,
unread: true,
}
})
jsfiddle: https://jsfiddle.net/gaotongfei/b2mjrzw6/1/
这是一段非常简短的用vuejs写的checkbox demo,但是点击其中的一个checkbox,剩下的都会被选中,请问哪里错了?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为你的input绑定的不是每个post自己的isread属性,而是唯一的一个isread属性,所以一改所有都改。
你的model需要重构,每个post应该是一个json对象而不是字符串。
因为你绑定了同一个model:
v-model="isread",点击后isread值为true,就都选中了