欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > uniapp App跳转微信小程序并互相传递参数、接收微信小程序传递的参数

uniapp App跳转微信小程序并互相传递参数、接收微信小程序传递的参数

2024/10/24 9:30:31 来源:https://blog.csdn.net/weixin_42333548/article/details/141216476  浏览:    关键词:uniapp App跳转微信小程序并互相传递参数、接收微信小程序传递的参数

1、App端跳转微信小程序(注意id一定是小程序的原始ID,在小程序后台设置-基本设置里可以看到)

注意:与微信小程序跳转微信小程序不同,App端不支持 uni.navigateToMiniProgram,App平台打开微信小程序,需要使用plus.share的 launchMiniProgram。

// App端跳转微信小程序
const appJumpMiniPro = () => {// 获取分享服务列表plus.share.getServices(res => {let sweixin: any = '';for (var i = 0; i < res.length; i++) {let t: any = res[i];if (t.id == 'weixin') {sweixin = t;}}if (sweixin) {sweixin.launchMiniProgram({id: 'gh_11af7705af70',  // 要跳转小程序的原始IDpath: ``,  //  可带参数type: 2   // 微信小程序版本类型可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。},// 目标小程序点击返回App后执行的回调,在此接收微信小程序传递的参数(res2: any) => {console.log(typeof res2, res2)// res2是微信小程序传递回来的参数 类型为string 需转化为js对象使用let result = JSON.parse(res2)console.log(result)// 拿到参数后执行你需要的逻辑},(err2: any) => {console.log(err2)});}else {uni.showToast({ icon: 'none', title: '当前环境不支持微信操作!' })}},err => {console.log(err)})
}

2、微信小程序端返回App端

下面的代码基于微信小程序也是uniapp开发的,原生的写法稍微有点不一样,详情见:打开 App | 微信开放文档。

<template><view class="page-container"><view class="">移动应用:{{appName}}</view><button class="bottom" open-type="launchApp" :app-parameter="JSON.stringify(form)" @error="launchAppError">返回APP</button></view>
</template><script>
export default {data() {return {appName: '',form: {cid: 4408111111111,libs: ['北京','上海']}}},onLoad(option) {console.log(option)this.appName = option.appName},methods: {launchAppError(e) {console.log(e.detail)uni.showToast({icon:'none', title:e.detail.errMsg})}}
}
</script>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com