当前位置:网站首页>uniapp微信小程序获取页面二维码(带有参数)
uniapp微信小程序获取页面二维码(带有参数)
2022-06-22 15:17:00 【杜蜜月】
1. 生成页面二维码(后端生成,前端需要将二维码写入文件管理器)
// 获取带参数的小程序码
async function getCodeImage() {
let param = {
id: 12345 };
let page = 'pages/index';
//getCodeBase64:调取后端接口,把参数和页面路径给后端
const codeBase64 = await getCodeBase64({
//扫描二维码后要跳到的那个页面的需要的参数
param,
//扫码二维码要跳到的页面的路径
page,
});
// const codeImgPath = `${wx.env.USER_DATA_PATH}/wxacode.png`;
const codeImgPath = `${
wx.env.USER_DATA_PATH}/${
param.id}.png`;
const getUrl = await getImageUrl(codeImgPath, codeBase64);
//二维码路径(可以用canvas画在海报里面)
return getUrl;
}
async function getImageUrl(codeImgPath, codeBase64) {
return new Promise((resolve) => {
//获取全局唯一的文件管理器
const fs = wx.getFileSystemManager();
//写文件
fs.writeFile({
filePath: codeImgPath,
data: codeBase64,
encoding: 'base64',
success: (res) => {
resolve(codeImgPath);
},
})
});
}
2. 扫描二维码后跳转的页面如何拿二维码参数
onMounted(() => {
//小程序扫描二维码之后会把页面参数赋到scene中,所以获取页面参数scene
//获取页面参数方法getLocationParams请看下方备注链接
const scene = getLocationParams('scene');
// 小程序码跳转过来
if (scene) {
console.log(scene);
//拿到页面参数,调取页面接口,渲染页面
}
});
备注:获取页面参数方法getLocationParams链接:https://blog.csdn.net/honeymoon_/article/details/124130295
边栏推荐
- 期货怎么开户?网上期货开户安全吗?
- 【C语言】深度剖析指针和数组的关系
- Simulation of stack and queue
- wallys/WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz
- Cmake tutorial series-00-introduction
- 全球首款AR隐形眼镜,元宇宙入口这次真的打开了?
- SAP ABAP 数据字典教程 SE11:表、锁定对象、视图和结构 -03
- SAP ABAP internal tables: create, read, populate, copy and delete-06
- Deploy odoo to the server and configure it as a service
- 什么是RESTful,REST api设计时应该遵守什么样的规则?
猜你喜欢
随机推荐
什么是 SAP ABAP? 类型、ABAP 完整形式和含义
论催收系统的任务调度设计
执行逻辑大同小异的实现类使用模板模式
Simulation of stack and queue
SLAM十四讲之第6讲--非线性优化
SAP ABAP data types, operators and editors-02
Gd32f4xx MCU drives MCP2515 to expand can interface
Google Chrome small details
4.字符串(倒序且大小写转换)
什么是RESTful,REST api设计时应该遵守什么样的规则?
Odoo local document function development record
SAP ABAP 对话框编程教程:中的模块池-09
Basic knowledge of audio and video | analysis of ANS noise suppression principle
【小程序项目开发-- 京东商城】uni-app开发之分包配置
天翼云乘风新基建,构建数字化转型“4+2”能力体系
静态断言 static_assert
接口幂等性设计
Program substitution function
十九、Xv6上下文切换(上下文切换的实现;状态机的封装与恢复)
Smart forms-014 in SAP ABAP








