-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7318026
commit ce35016
Showing
5 changed files
with
92 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,6 @@ export default { | |
name: TAG, | ||
// 混入v-model | ||
mixins: [ValueSync], | ||
props: { | ||
// 初始值 | ||
value: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* 广播 | ||
* @desc 向下广播 | ||
* @param {String} componentName 组件名 | ||
* @param {String} eventName 事件名 | ||
* @param {Object} params 参数 | ||
*/ | ||
function broadcast(componentName, eventName, params) { | ||
this.$children.forEach(child => { | ||
const name = child.$options.componentName | ||
if (name === componentName) { | ||
child.$emit.apply(child, [eventName].concat(params)) | ||
} else { | ||
broadcast.apply(child, [componentName, eventName].concat([params])) | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* 发布订阅 | ||
* 该组件参考 https://github.com/ElemeFE/element/blob/dev/src/mixins/emitter.js | ||
* 鸣谢 element团队 | ||
*/ | ||
export default { | ||
methods: { | ||
dispatch(componentName, eventName, params) { | ||
let parent = this.$parent || this.$root | ||
let name = parent.$options.componentName | ||
|
||
while (parent && (!name || name !== componentName)) { | ||
parent = parent.$parent | ||
|
||
if (parent) { | ||
name = parent.$options.componentName | ||
} | ||
} | ||
if (parent) { | ||
parent.$emit.apply(parent, [eventName].concat(params)) | ||
} | ||
}, | ||
broadcast(componentName, eventName, params) { | ||
broadcast.call(this, componentName, eventName, params) | ||
} | ||
} | ||
} |