GridGamePanel.onStateChange
基础库 2.82.0 开始支持本方法,这是一个同步方法。
绑定游戏推荐组件实例状态变化事件的监听器。
| 前提条件 | 无 |
| 业务背景 | 无 |
| 使用限制 | 无 |
| 注意事项 | 无 |
| 相关教程 | 无 |
语法
GridGamePanel.onStateChange(callback)
参数说明
callback
| 类型 | 默认值 | 必填 | 说明 | 最低支 持版本 |
|---|---|---|---|---|
| function | 是 | 状态变化事件的监听器 | 2.82.0 |
callback 是一个回调函数,接收 object 类型的参数,属性如下:
| 属性名 | 类型 | 说明 | 最低支持版本 |
|---|---|---|---|
| state | string | show | close | error|click,开发者调用hide接口 或 玩家点击组件右上角关闭组件,都会触发 close 事件 | 2.82.0 |
| errMsg | string | 错误信息,同 GridGamePanel.show 调用时返回的错误消息 | 2.82.0 |
| appName | string | state === 'click' 时返回,表示玩家点击的小游戏的名称 | 2.82.0 |
返回值
无
错误码
| errNo | errMsg | 说明 | 最低支持版本 |
|---|---|---|---|
| 999981 | In the gray scale experiment, the user will not display | 2.82.0 | |
| 21101 | GridGamePanel with the same gridCount can show most one | 2.82.0 | |
| 21102 | Fetch game list error | 小游戏框架内部错误,有需要请创建工单咨询 | 2.82.0 |
| 10301 | feature is not supported in app | 2.82.0 | |
| 20000 | internal error | 小游戏框架内部错误,有需要请创建工单咨询 | 2.82.0 |
| 20001 | invalid param | 2.82.0 | |
| 21000 | current game panel doesn't exist | 2.82.0 | |
| 21000 | @'operation' is illegal param | 2.82.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
let gridGamePanel = null; try { gridGamePanel = tt.createGridGamePanel({ gridCount: "nine", query: { tt00000000000000: "age=12&name=xxxx", }, }); } catch (error) { console.error("创建游戏推荐组件失败", error); } if (gridGamePanel) { gridGamePanel.onStateChange((res) => { console.log("游戏推荐组件状态变化", res); }); }
