Vue:当 Grandparent 或 parent 为 checked/unchecked 时,Check/uncheck 复选框
Vue: Check/uncheck checkbox when Grandparent or parent is checked/unchecked
所以当 grandparent 或 parent 是 checked/unchecked:
时,我试图 check/uncheck 一个复选框
new Vue({
el: '.app',
data: {
grand_parent: false,
parent: false
}
})
但是它不起作用,如下所示:
http://jsbin.com/yabewemimo/edit?html,js,output
我想达到的目标是:
- 当grand-parent为checked/unchecked时,它应该直接影响children,例如parent和child
- 当parent为checked/unchecked时,应该只影响child
感谢帮助
看来你还得看:
watch: {
grand_parent: function (val) {
if (val) this.parent = true;
}
}
您的代码没有按照您的预期工作,因为您的 parent 上有一个 v-model
,所以您的 :checked
属性 绑定没有效果。
new Vue({
el: '.app',
data: {
grand_parent: false,
parent_proxy: false // Because it will cause a stack overflow if
}, // I reference this.parent in its own computed
computed: {
parent: {
get () {
return (this.grand_parent)
? true
: this.parent_proxy
},
set (val) {
this.parent_proxy = val
}
}
}
})
正在工作bin
所以当 grandparent 或 parent 是 checked/unchecked:
时,我试图 check/uncheck 一个复选框new Vue({
el: '.app',
data: {
grand_parent: false,
parent: false
}
})
但是它不起作用,如下所示:
http://jsbin.com/yabewemimo/edit?html,js,output
我想达到的目标是:
- 当grand-parent为checked/unchecked时,它应该直接影响children,例如parent和child
- 当parent为checked/unchecked时,应该只影响child
感谢帮助
看来你还得看:
watch: {
grand_parent: function (val) {
if (val) this.parent = true;
}
}
您的代码没有按照您的预期工作,因为您的 parent 上有一个 v-model
,所以您的 :checked
属性 绑定没有效果。
new Vue({
el: '.app',
data: {
grand_parent: false,
parent_proxy: false // Because it will cause a stack overflow if
}, // I reference this.parent in its own computed
computed: {
parent: {
get () {
return (this.grand_parent)
? true
: this.parent_proxy
},
set (val) {
this.parent_proxy = val
}
}
}
})
正在工作bin