修改事件方法为现代语法
parent
da5e5fd4a4
commit
5ddb00e6b6
15
src/utils.js
15
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 <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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue