修改事件方法为现代语法
parent
da5e5fd4a4
commit
5ddb00e6b6
15
src/utils.js
15
src/utils.js
|
@ -6,18 +6,16 @@
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
export function $(selector, container) {
|
export function $(selector, container, multi) {
|
||||||
|
let fn = multi ? 'querySelectorAll' : 'querySelector'
|
||||||
if (container) {
|
if (container) {
|
||||||
return container.querySelector(selector)
|
return container[fn](selector)
|
||||||
}
|
}
|
||||||
return document.body.querySelector(selector)
|
return document.body[fn](selector)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function $$(selector, container) {
|
export function $$(selector, container) {
|
||||||
if (container) {
|
return $(selector, container, true)
|
||||||
return container.querySelectorAll(selector)
|
|
||||||
}
|
|
||||||
return document.body.querySelectorAll(selector)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const nextTick = (function () {
|
export const nextTick = (function () {
|
||||||
|
@ -192,8 +190,7 @@ export function clearOutsideClick(fn = noop) {
|
||||||
* @param stop <Boolean> 是否禁止事件冒泡
|
* @param stop <Boolean> 是否禁止事件冒泡
|
||||||
*/
|
*/
|
||||||
export function fire(el, name = 'click', data = {}, stop) {
|
export function fire(el, name = 'click', data = {}, stop) {
|
||||||
let ev = document.createEvent('Events')
|
let ev = new Event(name, { bubbles: !stop, cancelable: true })
|
||||||
ev.initEvent(name, !stop, true)
|
|
||||||
Object.assign(ev, data)
|
Object.assign(ev, data)
|
||||||
el.dispatchEvent(ev)
|
el.dispatchEvent(ev)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue