mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-15 04:42:23 +08:00
feat(mixins/bubblecallable): make component able to call its parents method
This commit is contained in:
parent
b90a61821f
commit
9efd312f99
25
packages/mixins/bubblecallable.js
Normal file
25
packages/mixins/bubblecallable.js
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user