h5跳转微信小程序 记录一下 仅前端uniapp

135 阅读1分钟

微信官方文档URL Link地址 developers.weixin.qq.com/miniprogram…

后端请求微信接口返回

{
 "errcode": 0,
 "errmsg": "ok",
 "url_link": "URL Link"
} 

前端请求后端的接口拿到URL Link (H5页面)

    this.$http({
        url: "api/index/weixin?pid="+urlData,  //需要传参数 pid就是前端自定义的参数
    }).then(res => {
        this.openlink = res.data.data.url_link
        if(this.openlink){
            location.href = this.openlink  //通过location跳转  可以直接跳转也可以事件之后跳转
        }else{
          //.....
        }
    }).catch(err => {
        console.log(err);
    });

跳转小程序后接收参数 onLoad (小程序)

onLoad(option){
    option.pid  //可以存到本地  需要用的时候做为参数
}