after-leave.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. exports.__esModule = true;
  3. exports.default = function (instance, callback) {
  4. var speed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 300;
  5. var once = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  6. if (!instance || !callback) throw new Error('instance & callback is required');
  7. var called = false;
  8. var afterLeaveCallback = function afterLeaveCallback() {
  9. if (called) return;
  10. called = true;
  11. if (callback) {
  12. callback.apply(null, arguments);
  13. }
  14. };
  15. if (once) {
  16. instance.$once('after-leave', afterLeaveCallback);
  17. } else {
  18. instance.$on('after-leave', afterLeaveCallback);
  19. }
  20. setTimeout(function () {
  21. afterLeaveCallback();
  22. }, speed + 100);
  23. };
  24. ; /**
  25. * Bind after-leave event for vue instance. Make sure after-leave is called in any browsers.
  26. *
  27. * @param {Vue} instance Vue instance.
  28. * @param {Function} callback callback of after-leave event
  29. * @param {Number} speed the speed of transition, default value is 300ms
  30. * @param {Boolean} once weather bind after-leave once. default value is false.
  31. */