[improvement] Checkbox: use relation mixin

This commit is contained in:
陈嘉涵
2019-05-07 10:20:14 +08:00
parent c1da495cb7
commit 444245d7e8
8 changed files with 24 additions and 36 deletions

View File

@@ -1,6 +1,10 @@
export function ChildrenMixin(parent) {
return {
inject: [parent],
inject: {
[parent]: {
default: null
}
},
computed: {
parent() {
@@ -18,11 +22,17 @@ export function ChildrenMixin(parent) {
},
beforeDestroy() {
this.parent.children = this.parent.children.filter(item => item !== this);
if (this.parent) {
this.parent.children = this.parent.children.filter(item => item !== this);
}
},
methods: {
bindRelation() {
if (!this.parent) {
return;
}
const { children } = this.parent;
if (children.indexOf(this) === -1) {