const {ccclass, property} = cc._decorator; @ccclass export default class IconBtn extends cc.Component { @property(cc.Sprite) btnSprite: cc.Sprite = null @property(cc.Label) titleLabel: cc.Label = null callback: (title: string) => void start () { } init(title: string, icon: cc.SpriteFrame) { this.btnSprite.spriteFrame = icon this.titleLabel.string = title } bindCallback(method: (title: string) => void) { this.callback = method } onBtnClicked() { this.callback && this.callback(this.titleLabel.string) } }