mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
42 lines
735 B
JavaScript
42 lines
735 B
JavaScript
export function ChildrenMixin(parent) {
|
|
return {
|
|
inject: [parent],
|
|
|
|
computed: {
|
|
parent() {
|
|
return this[parent];
|
|
},
|
|
|
|
index() {
|
|
return this.parent.children.indexOf(this);
|
|
}
|
|
},
|
|
|
|
created() {
|
|
const { children } = this.parent;
|
|
const index = this.parent.slots().indexOf(this.$vnode);
|
|
children.splice(index === -1 ? children.length : index, 0, this);
|
|
},
|
|
|
|
beforeDestroy() {
|
|
this.parent.children = this.parent.children.filter(item => item !== this);
|
|
}
|
|
};
|
|
}
|
|
|
|
export function ParentMixin(parent) {
|
|
return {
|
|
provide() {
|
|
return {
|
|
[parent]: this
|
|
};
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
children: []
|
|
};
|
|
}
|
|
};
|
|
}
|