click-outside.js 359 B

1234567891011121314151617
  1. import { on, off } from '../utils/event';
  2. export const ClickOutsideMixin = config => ({
  3. mounted() {
  4. config.handler = event => {
  5. if (!this.$el.contains(event.target)) {
  6. this[config.method]();
  7. }
  8. };
  9. on(document, config.event, config.handler);
  10. },
  11. beforeDestroy() {
  12. off(document, config.event, config.handler);
  13. }
  14. });