diff --git a/packages/mixins/bubblecallable.js b/packages/mixins/bubblecallable.js new file mode 100644 index 000000000..ac90fd41f --- /dev/null +++ b/packages/mixins/bubblecallable.js @@ -0,0 +1,25 @@ +export default { + methods: { + bubbleCall (componentName, functionName, ...params) { + let parent = this.$parent || this.$root + while (true) { + if (parent) { + const name = parent.$options.name + if (Array.isArray(componentName)) { + if (componentName.includes(name)) { + parent[functionName](...params) + break + } + } else { + if (name === componentName) { + parent[functionName](...params) + break + } + } + } + if (!parent || parent === this.$root) break + parent = parent.$parent + } + } + } +}