From d783fcf2f490f7ba5dc07fe969b94bec5e9412e4 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Mon, 14 Sep 2020 20:43:30 +0800 Subject: [PATCH] chore: remove closeOnPopstate mixin --- src/mixins/close-on-popstate.js | 44 --------------------------------- src/popup/index.js | 12 ++++++--- 2 files changed, 9 insertions(+), 47 deletions(-) delete mode 100644 src/mixins/close-on-popstate.js diff --git a/src/mixins/close-on-popstate.js b/src/mixins/close-on-popstate.js deleted file mode 100644 index ed98c5c18..000000000 --- a/src/mixins/close-on-popstate.js +++ /dev/null @@ -1,44 +0,0 @@ -import { on, off } from '../utils/dom/event'; -import { BindEventMixin } from './bind-event'; - -export const CloseOnPopstateMixin = { - mixins: [ - BindEventMixin(function (bind, isBind) { - this.handlePopstate(isBind && this.closeOnPopstate); - }), - ], - - props: { - closeOnPopstate: Boolean, - }, - - data() { - return { - bindStatus: false, - }; - }, - - watch: { - closeOnPopstate(val) { - this.handlePopstate(val); - }, - }, - - methods: { - handlePopstate(bind) { - /* istanbul ignore if */ - if (this.$isServer) { - return; - } - - if (this.bindStatus !== bind) { - this.bindStatus = bind; - const action = bind ? on : off; - action(window, 'popstate', () => { - this.close(); - this.shouldReopen = false; - }); - } - }, - }, -}; diff --git a/src/popup/index.js b/src/popup/index.js index 34b5daeeb..4b6ee6fec 100644 --- a/src/popup/index.js +++ b/src/popup/index.js @@ -13,9 +13,9 @@ import { import { createNamespace, isDef } from '../utils'; // Composition +import { useEventListener } from '@vant/use'; import { useLockScroll } from '../composition/use-lock-scroll'; import { useLazyRender } from '../composition/use-lazy-render'; -import { CloseOnPopstateMixin } from '../mixins/close-on-popstate'; // Components import Icon from '../icon'; @@ -68,8 +68,6 @@ export const popupSharedProps = { }; export default createComponent({ - mixins: [CloseOnPopstateMixin], - inheritAttrs: false, props: { @@ -77,6 +75,7 @@ export default createComponent({ round: Boolean, closeable: Boolean, transition: String, + closeOnPopstate: Boolean, safeAreaInsetBottom: Boolean, position: { type: String, @@ -237,6 +236,13 @@ export default createComponent({ } ); + useEventListener('popstate', () => { + if (props.closeOnPopstate) { + close(); + shouldReopen = false; + } + }); + onMounted(() => { if (props.show) { open();