[improvement] rename packages dir to src (#3659)

This commit is contained in:
neverland
2019-06-27 11:25:57 +08:00
committed by GitHub
parent 8489918dca
commit 75c79b7044
619 changed files with 21 additions and 21 deletions
+68
View File
@@ -0,0 +1,68 @@
export function ChildrenMixin(parent, options = {}) {
const indexKey = options.indexKey || 'index';
return {
inject: {
[parent]: {
default: null
}
},
computed: {
parent() {
return this[parent];
},
[indexKey]() {
this.bindRelation();
return this.parent.children.indexOf(this);
}
},
created() {
this.bindRelation();
},
beforeDestroy() {
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) {
const vnodeIndex = this.parent.slots().indexOf(this.$vnode);
if (vnodeIndex === -1) {
children.push(this);
} else {
children.splice(vnodeIndex, 0, this);
}
}
}
}
};
}
export function ParentMixin(parent) {
return {
provide() {
return {
[parent]: this
};
},
data() {
return {
children: []
};
}
};
}