当前位置:网站首页>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
边栏推荐
- 4. string (reverse order and case conversion)
- Static assertion static_ assert
- 浙江创投圈的“半壁江山”,还得是国资
- odoo部署到服务器并配置为服务
- SAP ABAP 子屏幕教程:在 SAP 中调用子屏幕-010
- Opensql and native sql-05 in SAP ABAP the purpose of this tutorial is not to teach you SQL or database concepts
- 如何为政企移动办公加上一道“安全锁”?
- 6.gui (graphics, filling)
- 【小程序项目开发-- 京东商城】uni-app开发之配置tabBar & 窗口样式
- User exit and customer exit in SAP ABAP -015
猜你喜欢
随机推荐
执行逻辑大同小异的实现类使用模板模式
在JFlash中添加未知类型的单片机
用递归法求Fibonacci数列第n项的值
[VTK] model rotation and Translation
【山大会议】项目初始化
Google Chrome small details
SLAM十四讲之第6讲--非线性优化
浙江创投圈的“半壁江山”,还得是国资
【山大会议】使用TypeScript为项目进行重构
Gd32f4xx MCU drives MCP2515 to expand can interface
Conversion between numeric types and strings
Program substitution function
Ironsource Luna offers a limited time discount for Apple search ads and enjoys 3 months of free service upon registration
预约打新债到底安不安全呀?是不是靠谱的?
实现一个Container全局组件步骤(给还不会使用组件的新手一个思路,大佬绕道)
Test for API
The odoo system sets priorities for the views independently developed by the original model
SAP ABAP report programming-08
大话局部性原理
IO模型的5中模式









