vue add event — don’t forget to remove your event

Kevin Hu
1 min readJun 14, 2017

There are some situation when we use vue to develop our app:

Scenario:

  1. When we use vue to develop our app component like Modal, Dropdown…etc. We may need to add event listener to document to handle click outside event. We should always remember to add event and “remove” when it destroy!!
  2. We may use some library in our vue project like: webVR aframe. When we use it in our project. it may destroy when page change. so… don’t forget to remove the event!!
  3. other situation…

Vue’s directive will handle all the things when we use @click, @mousemove, etc. We may forget to handle our custom event when we add it. This article just remind every vue developer don’t forget this when you develop your app.

Thanks

--

--

Kevin Hu

— — Frontend Developer —— my personal website: https://sky790312-v2.web.app — — — — — — — — — — — my consultation site: https://f2e-camp.web.app/