on与off函数里的参数中 evt:去掉试试?
/** A minimal event emitter. */
class EventEmitter {
/** Constructs a new event emitter instance. */
constructor();
/**
* Registers an event listener.
* @param evt Event name
* @param fn Listener
* @param [ctx] Listener context
* @returns `this`
*/
public on(evt: string, fn: EventEmitterListener, ctx?: any): this;
/**
* Removes an event listener or any matching listeners if arguments are omitted.
* @param [evt] Event name. Removes all listeners if omitted.
* @param [fn] Listener to remove. Removes all listeners of `evt` if omitted.
* @returns `this`
*/
public off(evt?: string, fn?: EventEmitterListener): this;
/**
* Emits an event by calling its listeners with the specified arguments.
* @param evt Event name
* @param args Arguments
* @returns `this`
*/
public emit(evt: string, ...args: any[]): this;
}
on方法中的evt参数是必填的,不能去掉
eventUtils.ts
import { EventTarget } from ‘cc’
export default new EventTarget()
import eventTarget from "../../utils/eventUtils"
eventTarget.on('gghh', this._agreeEvent, this)
import eventTarget from "../../utils/eventUtils"
eventTarget.emit('gghh')
这样可以了