mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
38 lines
658 B
JavaScript
38 lines
658 B
JavaScript
export function ChildrenMixin(parent) {
|
|
return {
|
|
inject: [parent],
|
|
|
|
computed: {
|
|
parent() {
|
|
return this[parent];
|
|
}
|
|
},
|
|
|
|
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: []
|
|
};
|
|
}
|
|
};
|
|
}
|