From b5fcf67b53883f8cfbb915d2ff4ab92988c16a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Mon, 16 Dec 2019 12:08:29 +0800 Subject: [PATCH] Affix add useCapture prop --- src/components/affix/affix.vue | 12 ++++++++---- src/utils/dom.js | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/affix/affix.vue b/src/components/affix/affix.vue index c0716d8c..1ab8f18d 100644 --- a/src/components/affix/affix.vue +++ b/src/components/affix/affix.vue @@ -48,6 +48,10 @@ }, offsetBottom: { type: Number + }, + useCapture: { + type: Boolean, + default: false } }, data () { @@ -78,8 +82,8 @@ mounted () { // window.addEventListener('scroll', this.handleScroll, false); // window.addEventListener('resize', this.handleScroll, false); - on(window, 'scroll', this.handleScroll); - on(window, 'resize', this.handleScroll); + on(window, 'scroll', this.handleScroll, this.useCapture); + on(window, 'resize', this.handleScroll, this.useCapture); this.$nextTick(() => { this.handleScroll(); }); @@ -87,8 +91,8 @@ beforeDestroy () { // window.removeEventListener('scroll', this.handleScroll, false); // window.removeEventListener('resize', this.handleScroll, false); - off(window, 'scroll', this.handleScroll); - off(window, 'resize', this.handleScroll); + off(window, 'scroll', this.handleScroll, this.useCapture); + off(window, 'resize', this.handleScroll, this.useCapture); }, methods: { handleScroll () { diff --git a/src/utils/dom.js b/src/utils/dom.js index 26a228e0..dcaf1927 100644 --- a/src/utils/dom.js +++ b/src/utils/dom.js @@ -4,9 +4,9 @@ const isServer = Vue.prototype.$isServer; /* istanbul ignore next */ export const on = (function() { if (!isServer && document.addEventListener) { - return function(element, event, handler) { + return function(element, event, handler, useCapture = false) { if (element && event && handler) { - element.addEventListener(event, handler, false); + element.addEventListener(event, handler, useCapture); } }; } else { @@ -21,9 +21,9 @@ export const on = (function() { /* istanbul ignore next */ export const off = (function() { if (!isServer && document.removeEventListener) { - return function(element, event, handler) { + return function(element, event, handler, useCapture = false) { if (element && event) { - element.removeEventListener(event, handler, false); + element.removeEventListener(event, handler, useCapture); } }; } else {