当前位置:网站首页>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
边栏推荐
- SAP ABAP 内部表:创建、读取、填充、复制和删除-06
- Gd32f4xx MCU drives MCP2515 to expand can interface
- What is the relationship between CSC securities and qiniu school? Is it safe to open a securities account
- 二叉树练习第二弹
- 让pycharm项目里面的文本模板支持jinjia2语法
- Lecture 6 of slam Lecture 14 -- nonlinear optimization
- [Shanda conference] peer connection based on webrtc
- [Shanda conference] software performance optimization and bug repair
- SAP价值流程&帮助请求流程-011
- How to embody the value of knowledge management in business
猜你喜欢
随机推荐
Focus on creating a net red product. The xinjietu x70s is newly launched, starting from 87900
Test for API
【小程序项目开发-- 京东商城】uni-app开发之轮播图
Ironsource Luna offers a limited time discount for Apple search ads and enjoys 3 months of free service upon registration
Deploy odoo to the server and configure it as a service
长安链使用技巧总结
机器学习笔记 - HaGRID—手势识别图像数据集简介
对ABAP程序调优的学习(四)LOOP WHERE KEY
5. reading and writing of documents (students)
SAP ABAP BAPI-016
CMake教程系列-00-简介
接口幂等性设计
SAP ABAP table control and example-07
ABAP query tutorial in sap: sq01, sq02, sq03-017
[Shanda conference] application setting module
[Shanda conference] software performance optimization and bug repair
Opensql and native sql-05 in SAP ABAP the purpose of this tutorial is not to teach you SQL or database concepts
SAP ABAP data types, operators and editors-02
安全信得过!天翼云数据安全管理平台通过评测
【C语言】深度剖析指针和数组的关系









