Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当不使用 vue-router 时,vm.$options.destroyed 为 undefined 问题 #6

Closed
tangdaohai opened this issue Sep 10, 2021 · 0 comments
Closed

Comments

@tangdaohai
Copy link
Owner

此部分代码:

vue-happy-bus/index.js

Lines 30 to 36 in 22c62b8

const destroyed = vm.$options.destroyed
// 当前组件的唯一标示(vue生成的自增ID)
const uid = vm._uid
// 初始化当前组件的事件集合对象
EventStore[uid] = {}
// 为当前组件挂载destroyed钩子
!destroyed.includes(destroyHandler) && destroyed.push(destroyHandler)


因为 vue-router 默认会mixin destroyed 事件,当不使用 vue-router 组件时,没有默认的监听 destroyed 行为,vue 内部不会创建 destroyed Array。

参考:
https://github.com/vuejs/vue-router/blob/ce955d9322d54c9e1f05ea5f8566aaa408587b71/src/install.js#L21-L36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant