1. 需求:在一个java后端+vue3前端(vant4)的项目中,点击某个按钮跳转到指定的微信小程序的指定页面,并提供传参,微信小程序能正常打开(在微信已登录的环境下)
2. 准备:
微信小程序:企业注册版本
3. 开发:
console.log('测试跳转小程序');
let query ={
contractCode: "A20220802002",
scanCode: "测试跳转小程序",
ingoUrl: "",
brandId: "",
userId: "",
userName: ""
}
// 把对象转换成 a=1&b=2&c=3&d=4 的字符串格式
let queryString = Object.keys(query).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`).join('&')
// 对其进行转码
let res = encodeURIComponent(queryString)
console.log('queryString',queryString);
window.location.href = "weixin://dl/business/?appid=xxxxxxxxxx&path=pages/index/Index&env_version=trial&query="+res;
4. 小程序使用onload函数,获取被调用时收到的参数即可
觉得有帮助的朋友可以支持下作者哦,您的鼓励是我创作的最大动力,如有开发问题可联系作者

4112

被折叠的 条评论
为什么被折叠?



