Skip to content

Commit

Permalink
fix(index.js): 兼容 vm.$options.destroyed 可能为 undefined 的场景 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
tangdaohai committed Sep 10, 2021
1 parent 89d47d4 commit ad3aa87
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const destroyHandler = function () {

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

return {
$on: (type, handler) => {
Expand Down

0 comments on commit ad3aa87

Please sign in to comment.