chore: remove mixin extend

This commit is contained in:
chenjiahan
2020-07-01 17:12:50 +08:00
parent 02e288e3cb
commit 1b58e872fd
6 changed files with 55 additions and 97 deletions
+76
View File
@@ -0,0 +1,76 @@
import Vue from 'vue';
import { sortChildren } from '../utils/vnodes';
export function ChildrenMixin(parent, options = {}) {
const indexKey = options.indexKey || 'index';
return {
inject: {
[parent]: {
default: null,
},
},
computed: {
parent() {
if (this.disableBindRelation) {
return null;
}
return this[parent];
},
[indexKey]() {
this.bindRelation();
if (this.parent) {
return this.parent.children.indexOf(this);
}
return null;
},
},
mounted() {
this.bindRelation();
},
beforeDestroy() {
if (this.parent) {
this.parent.children = this.parent.children.filter(
(item) => item !== this
);
}
},
methods: {
bindRelation() {
if (!this.parent || this.parent.children.indexOf(this) !== -1) {
return;
}
const children = [...this.parent.children, this];
sortChildren(children, this.parent);
this.parent.children = children;
},
},
};
}
export function ParentMixin(parent) {
return {
provide() {
return {
[parent]: this,
};
},
data() {
return {
children: [],
};
},
};
}