获取小程序码参数scene?

发布于 7 年前作者 yfang3814 次浏览最后编辑 7 年前来自 issues

我这样获取scene有不对的地方吗?打印query为空

onLoad:function(query) {

    let that = this;

    if (query.scene){

      const scene = decodeURIComponent(query.scene)

      var id = scene.split(‘&’)[0].split(‘=’)[1]

      var shopName = scene.split(‘&’)[1].split(‘=’)[1]

      that.setData({

        sid: id,

        shopName: shopName

      })

    }

}

3 回复
fanghan
fanghan1 楼6 年前

感觉没什么问题,只是代码很容易报错。尽量先判断 scene.split(‘&’).length >= 2 再进行后边的操作

liaoming
liaoming2 楼6 年前

获取scene的方式是对的。出错的时候,query打印出来是什么?如果是空,要么你不是扫码进的,要么你生成的二维码scene设置错了。

naxie
naxie3 楼5 年前

你好,请问你是如何打印出信息来的?我扫二维码进入小程序,完全看不到这个数值