From 5ddb00e6b6bb25133810ec175c20060716c8084e Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 9 May 2023 14:08:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=8B=E4=BB=B6=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=BA=E7=8E=B0=E4=BB=A3=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/utils.js b/src/utils.js index b489be7..ff444d6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,18 +6,16 @@ function noop() {} -export function $(selector, container) { +export function $(selector, container, multi) { + let fn = multi ? 'querySelectorAll' : 'querySelector' if (container) { - return container.querySelector(selector) + return container[fn](selector) } - return document.body.querySelector(selector) + return document.body[fn](selector) } export function $$(selector, container) { - if (container) { - return container.querySelectorAll(selector) - } - return document.body.querySelectorAll(selector) + return $(selector, container, true) } export const nextTick = (function () { @@ -192,8 +190,7 @@ export function clearOutsideClick(fn = noop) { * @param stop 是否禁止事件冒泡 */ export function fire(el, name = 'click', data = {}, stop) { - let ev = document.createEvent('Events') - ev.initEvent(name, !stop, true) + let ev = new Event(name, { bubbles: !stop, cancelable: true }) Object.assign(ev, data) el.dispatchEvent(ev) }