uniapp在App端跳转微信小程序

109 阅读1分钟

uniapp在App端跳转微信小程序

个人应用场景为:接第三方的微信支付需要去小程序获取openID,从而需要跳转小程序并通过path传参

时间:2025.10.14

首先在manifast.json 设置share

image.png

在要跳转的.vue文件页面



	onLoad(option) {
		const that = this
		// #ifdef APP-PLUS  
		console.log("plus");  
		plus.share.getServices(function(s){  
				var shares={};  
				for (var i = 0; i < s.length; i++) {  
					var t=s[i];  
					console.log(t);  
					shares[t.id]=t;  
					console.log(t.id);  
				}  
        
				var sweixin=shares['weixin'];  
				// Vue 语法直接赋值
				that.sweixin = sweixin;

			}, function(e){  
				console.log("获取分享服务列表失败:"+e.message);  
			});  
		//#endif


		
	},

data里定义sweixin变量


data() {
    return {
        sweixin: null, 
    }

}

methods 里的函数(我是绑在按钮上触发的)

launchMiniProgram里的

id为微信小程序原始id(必传),

path为跳转的路径(可选),

type为小程序版本类型(可选)


kanshipin() {  
      	var n = this;  
		  console.log(n.sweixin,'n.sweixin');
      //#ifdef APP-PLUS  
        console.log(n.sweixin);
		  
        n.sweixin?n.sweixin.launchMiniProgram({  
            id:'gh_7dd2********',
			path: 'pages/activity/activity?user="123123213"&id="123123213"',  // 小程序页面路径(可选)
			type: 0,                // 小程序版本类型(可选)  
        }):plus.nativeUI.alert('当前环境不支持微信操作!');  

      //#endif  
	},