vue3-yuanma/packages/runtime-test/src/triggerEvent.ts

22 lines
449 B
TypeScript
Raw Normal View History

2018-10-28 21:43:27 +00:00
import { TestElement } from './nodeOps'
export function triggerEvent(
el: TestElement,
event: string,
payload: any[] = []
) {
const { eventListeners } = el
if (eventListeners) {
const listener = eventListeners[event]
if (listener) {
if (Array.isArray(listener)) {
for (let i = 0; i < listener.length; i++) {
listener[i](...payload)
}
} else {
listener(...payload)
}
}
}
}