mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 02:31:21 +00:00
[improvement] add bind event mixin
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { use } from '../utils';
|
||||
import { stopPropagation } from '../utils/event';
|
||||
import { BindEventMixin } from '../mixins/bind-event';
|
||||
import Key from './Key';
|
||||
|
||||
const [sfc, bem, t] = use('number-keyboard');
|
||||
@@ -7,6 +8,14 @@ const CLOSE_KEY_TYPE = ['blue', 'big'];
|
||||
const DELETE_KEY_TYPE = ['delete', 'big', 'gray'];
|
||||
|
||||
export default sfc({
|
||||
mixins: [
|
||||
BindEventMixin(function (bind) {
|
||||
if (this.hideOnClickOutside) {
|
||||
bind(document.body, 'touchstart', this.onBlur);
|
||||
}
|
||||
})
|
||||
],
|
||||
|
||||
props: {
|
||||
show: Boolean,
|
||||
title: String,
|
||||
@@ -39,22 +48,6 @@ export default sfc({
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.handler(true);
|
||||
},
|
||||
|
||||
destroyed() {
|
||||
this.handler(false);
|
||||
},
|
||||
|
||||
activated() {
|
||||
this.handler(true);
|
||||
},
|
||||
|
||||
deactivated() {
|
||||
this.handler(false);
|
||||
},
|
||||
|
||||
watch: {
|
||||
show() {
|
||||
if (!this.transition) {
|
||||
@@ -92,21 +85,6 @@ export default sfc({
|
||||
},
|
||||
|
||||
methods: {
|
||||
handler(action) {
|
||||
/* istanbul ignore if */
|
||||
if (this.$isServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (action !== this.handlerStatus && this.hideOnClickOutside) {
|
||||
this.handlerStatus = action;
|
||||
document.body[(action ? 'add' : 'remove') + 'EventListener'](
|
||||
'touchstart',
|
||||
this.onBlur
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
onBlur() {
|
||||
this.$emit('blur');
|
||||
},
|
||||
|
Reference in New Issue
Block a user