微信小程序能正常跳转到另一个小程序的前提是:这两个小程序被同一个微信公众号关联,否则无法跳转。代码如下:
wx.navigateToMiniProgram({
appId: ‘xxxxxxxxxxxxxx’,
path: ‘’,
extraData: {
user_id: 111,
store_id: 222,
userName: ‘张三’
},
envVersion: ‘release’,
success(res)
{
console.log(‘跳转成功’);
}
})
注意:这里传递了三个参数,分别是user_id,store_id和userName,接下来要在第二个小程序中获取这三个参数。获取代码写在app.js中的onlunch()函数中,启动的时候就获取,(也可以在onshow()函数中获取)代码如下:
data: {
“user_id”: ‘’,
“store_id”: ‘’,
“userName”: ‘’
},
onLaunch: function(options)
{
console.log(this.data)
console.log(options.referrerInfo.extraData)
//启动时获取参数
this.data.user_id = options.referrerInfo.extraData.user_id;
this.data.store_id = options.referrerInfo.extraData.store_id;
this.data.userName = options.referrerInfo.extraData.userName;
//将用户id,店铺id,用户名放到缓存中
wx.setStorageSync("userinformation", this.data);
var u = wx.getStorageSync("userinformation")
console.log('22222222' + u.store_id);
},
二、小程序跳转的一些场景值
wx.getLaunchOptionsSync() 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致
1011 扫描二维码
1047 扫描小程序码