找到开发目录下面的 》 【开发管理】》【开发设置】找到【扫普通链接二维码打开小程序】模块,
如图:
点击【添加】
例如:
我的生成二维码的链接地址是
服务器请求地址+需要跳转的参数
我要跳转到资讯页面,
服务器域名:https://xxxxx.com
资讯页面路径:/pagesA/information/informationDetails,
查询参数:id=12(参数不定)
const params = “path=/pagesA/information/informationDetails?id=12”
const paramsEncode=encodeURIComponent(params);//对拼接跳转参数进行编码:
console.log(paramsEncode);
//编码结果:path%3D%2FpagesA%2Finformation%2FinformationDetails%3Fid%3D12
生成二维码链接:草料二维码生成网站
https://xxxxx.com?path%3D%2FpagesA%2Finformation%2FinformationDetails%3Fid%3D12
如图:我实际跳转页面参数
onLoad(options) {console.log("[middle]", options)if (options.hasOwnProperty('q') && options.q) {//对参数进行解码const tempUrl = decodeURIComponent(options.q);//对解码后的参数进行拆分组装,获取要跳转的路径const paramsObject = this.urlParams(tempUrl);uni.redirectTo({url: paramsObject})} else {uni.switchTab({url: "/pages/index/index"})}
},methods: {urlParams(url) {let str = decodeURIComponent(url.slice(url.indexOf('?') + 1))let path = str.slice(str.indexOf('=') + 1);return path},}
详细内容请详读官方文档
注:
体验版:配置的测试链接需要和二维码生成的链接地址一摸一样,不能生成动态参数
测试:xxx.com?path%3D%2FpagesA%2Finformation%2FinformationDetails%3Fid%3D12
线上版:配置的测试链接只需要填写域名和跳转页面,如:id不需要编码填进测试链接
正式:xxx.com?path%3D%2FpagesA%2Finformation%2FinformationDetails
上一篇: 西递经典导游词
下一篇:一步之遥的精典台词有哪些