chore: move mixins

This commit is contained in:
chenjiahan
2020-07-05 16:00:10 +08:00
parent 3a2e20eb52
commit 4a25ebf9ab
14 changed files with 844 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
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;
});
}
},
},
};