eventemitter - 为什么 vuejs3 应用程序中的发射器不捕获事件?
问题描述
在我的 vuejs3/bootstrap 4.3.1 应用程序中使用 "mitt": "^2.1.0" 我有一个页面,其中包含项目和子组件,当操作员单击此子组件的按钮时触发事件 listingHeaderRightButtonClickedEvent:
export default {
setup () {
function triggerListingHeaderRightButtonClickedEvent () {
console.log('SOURCE triggerListingHeaderRightButtonClickedEvent parentComponentKey::')
console.log(parentComponentKey) // IN BROWSER'S CONSOLE I SEE THIS OUTPUT
emitter.emit('listingHeaderRightButtonClickedEvent', { parentComponentKey: this.parentComponentKey })
}
在父页面中,我尝试捕获此事件:
const emitter = mitt()
export default {
setup () {
emitter.on('listingHeaderRightButtonClickedEvent', params => {
console.log('TARGET listingHeaderRightButtonClickedEvent params::')
console.log(params) // IN BROWSER'S CONSOLE THIS EVENT IS NOT TRIGGERED
if (params.parentComponentKey === 'category') {
console.log('!!!!!loadCategories::')
loadCategories()
}
})
console.log('adminCategoriesListInit emitter::')
console.log(emitter)
输出 emmiter 对象我看到:https ://imgur.com/a/SmHD2Gz 有什么问题?
谢谢!
解决方案
推荐阅读
- python - Pandas 数据框合并无法通过多列相等检查按预期工作
- python - 从“lxml.etree 模块的_ElementUnicodeResult 对象”创建列表对象
- java - 遇到 java.net.BindException:服务器-客户端套接字应用程序上的地址已在使用中(绑定失败)
- linux - 使用 ORS、NR、FS、RS 的 awk 命令说明
- android - 如何将 mp3 文件(android 和 ios)传输到应用程序以使用颤振上传到 fire_storage?
- javascript - 如何创建和更改数组中的颜色
- java - 如果它不是 ArrayList 中的唯一值,如何循环提示用户输入?
- mysql - 用 UNION 选择 DISTINCT
- c++ - 如何通过像素完美缩放/移动修复 SFML 中顶点数组中的垂直伪影线?
- swagger - 使用 Swagger 2.0,如何显示一个模型,它是一个接受多种类型的数组?