抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • API 概览
  • C# API
  • 开放接口
  • 收藏
  • 群聊
  • 关注
  • 数据分析
  • 基础
  • 渲染
  • 设备
  • 文件
  • 位置
  • 媒体
  • 网络
  • 转发
  • 数据缓存
  • 广告
  • tt.createGridGamePanel
  • tt.createRewardedVideoAd
  • tt.createBannerAd
  • tt.createInterstitialAd
  • BannerAd
  • RewardedVideoAd
  • InterstitialAd
  • GridGamePanel
  • GridAd
  • GridGamePanel
  • GridGamePanel.show
  • GridGamePanel.hide
  • GridGamePanel.onStateChange
  • GridGamePanel.offStateChange
  • GridGamePanel.destroy
  • 界面
  • 支付
  • Worker
  • GridGamePanel.onStateChange

    收藏
    我的收藏

    基础库 2.82.0 开始支持本方法,这是一个同步方法。

    绑定游戏推荐组件实例状态变化事件的监听器。

    前提条件
    业务背景
    使用限制
    注意事项
    相关教程

    语法

    GridGamePanel.onStateChange(callback)

    参数说明

    callback

    类型默认值必填说明最低支持版本
    function
    状态变化事件的监听器
    2.82.0

    callback 是一个回调函数,接收 object 类型的参数,属性如下:

    属性名类型说明最低支持版本
    statestring
    show | close | error|click,开发者调用hide接口 或 玩家点击组件右上角关闭组件,都会触发 close 事件
    2.82.0
    errMsgstring

    错误信息,同 GridGamePanel.show 调用时返回的错误消息

    2.82.0
    appNamestring
    state === 'click' 时返回,表示玩家点击的小游戏的名称
    2.82.0

    返回值

    错误码

    errNoerrMsg说明最低支持版本
    999981In the gray scale experiment, the user will not display
    2.82.0
    21101GridGamePanel with the same gridCount can show most one
    2.82.0
    21102Fetch game list error
    小游戏框架内部错误,有需要请创建工单咨询
    2.82.0
    10301feature is not supported in app
    2.82.0
    20000internal error
    小游戏框架内部错误,有需要请创建工单咨询
    2.82.0
    20001invalid param
    2.82.0
    21000current 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); }); }