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) }