注册新组件

January 20, 2020 · View on GitHub

1、获取组件基类BaseComponent

const BaseComponent = GoldPlay.getComponent('BaseComponent')

2、定义自己的组件类,该类继承BaseComponent

class ButtonComponent extends BaseComponent { ... }

3、注册组件到GoldPlay,显示在control bar右侧第二个位置

GoldPlay.registerComponent('buttonComponent', ButtonComponent, 'right', 1)

4、为使新组件的初始化属性函数、绑定事件函数等生效,需要在新组件中定义registerMethod方法,在该方法中调用要生效的函数

registerMethod() {

  this.initProps()

  this.bindEvent()

}