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

Popover组件在非自主销毁时会报 Cannot read property 'removeEventListener' of undefined #4

Closed
daLingZhong opened this issue Sep 4, 2018 · 1 comment

Comments

@daLingZhong
Copy link

    mounted () {
      if (this.trigger === 'click') {
        this.$refs.popover.addEventListener('click', this.onClick)
      } else {
        this.$refs.popover.addEventListener('mouseenter', this.open)
        this.$refs.popover.addEventListener('mouseleave', this.close)
      }
    },
    destroyed () {
      if (this.trigger === 'click') {
        this.$refs.popover.removeEventListener('click', this.onClick)
      } else {
        this.$refs.popover.removeEventListener('mouseenter', this.open)
        this.$refs.popover.removeEventListener('mouseleave', this.close)
      }
    },

应该是没有hover或者click触发时组件并不会被实例化,导致eventListener没有被添加,在最后destroyed时就会找不到这个事件监听器,就会出现无法移除报错情况

@FrankFang
Copy link
Owner

嗯,我应该用 beforeDestroy

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

2 participants