跳转的小程序:
在本小程序pages.json里声明要跳转到的小程序的appid
在pages.json写上 要跳转的小程序的id
"navigateToMiniProgramAppIdList":["要跳转的小程序的appid"]
如下图
页面跳转触发事件代码:
小程序A到B,使用到的函数:wx.navigateToMiniProgram(Object object)
小程序B到A,使用到的函数:wx.navigateBackMiniProgram(Object object)
skip() {
uni.navigateToMiniProgram({
// appid 写你要跳转的小程序的 appid
appId: '写你要跳转的小程序的 appid',
// 路径写 src下的路径,假如你跳转的是pages下的页面,就可以写pages/index
path: 'my/index?id=1545243840380669954',
extraData: {
// 'type': 'out'
},
// 这个不写的话会显示开发环境,不能正常跳转,写上就能正常跳转了
envVersion: 'develop',
success(res) {
// 打开成功
uni.showToast({
title: '跳转成功'
})
},
fail(err) {
// 打开失败/取消
uni.showToast({
title: '跳转不成功'
})
}
})
}
#下图是uni.navigateToMiniProgram(OBJECT) 的 api;
具体可以看https://uniapp.dcloud.net.cn/api/other/open-miniprogram.html#navigatetominiprogram
另一个小程序接收数据:接受传过来的参数:
onLoad(e) {
// 监听外部传过来的id
uni.onAppShow((res) => {
if (JSON.stringify(res.query) !== '{}' && res.referrerInfo.appId == "本小程序appid") {
if(res.query.id){
this.id= res.query.id;
}else{
uni.navigateTo({
url: `../pages/home/home/index`
})
return
}
}
})
}