click-outside.js 492 B

12345678910111213141516171819
  1. import { on, off } from '../utils/event';
  2. export var ClickOutsideMixin = function ClickOutsideMixin(config) {
  3. return {
  4. mounted: function mounted() {
  5. var _this = this;
  6. config.handler = function (event) {
  7. if (!_this.$el.contains(event.target)) {
  8. _this[config.method]();
  9. }
  10. };
  11. on(document, config.event, config.handler);
  12. },
  13. beforeDestroy: function beforeDestroy() {
  14. off(document, config.event, config.handler);
  15. }
  16. };
  17. };