修改事件方法为现代语法

pull/1/head
yutent 2023-05-09 14:08:31 +08:00
parent da5e5fd4a4
commit 5ddb00e6b6
1 changed files with 6 additions and 9 deletions

View File

@ -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 <Boolean> 是否禁止事件冒泡
*/
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)
}