mirror of
https://github.com/youzan/vant.git
synced 2026-05-06 01:00:26 +08:00
perf: remove passive event polyfill (#9590)
This commit is contained in:
@@ -2,22 +2,6 @@ import { Ref, watch, isRef, unref, onUnmounted, onDeactivated } from 'vue';
|
||||
import { onMountedOrActivated } from '../onMountedOrActivated';
|
||||
import { inBrowser } from '../utils';
|
||||
|
||||
// eslint-disable-next-line
|
||||
export let supportsPassive = false;
|
||||
|
||||
if (inBrowser) {
|
||||
try {
|
||||
const opts = {};
|
||||
Object.defineProperty(opts, 'passive', {
|
||||
get() {
|
||||
supportsPassive = true;
|
||||
},
|
||||
});
|
||||
window.addEventListener('test-passive', null as any, opts);
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
type TargetRef = EventTarget | Ref<EventTarget | undefined>;
|
||||
|
||||
export type UseEventListenerOptions = {
|
||||
@@ -43,11 +27,7 @@ export function useEventListener(
|
||||
const element = unref(target);
|
||||
|
||||
if (element && !attached) {
|
||||
element.addEventListener(
|
||||
type,
|
||||
listener,
|
||||
supportsPassive ? { capture, passive } : capture
|
||||
);
|
||||
element.addEventListener(type, listener, { capture, passive });
|
||||
attached = true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user