微信小程序 - 二維碼生成工具
下載:weapp-qrcode.js 文件
github: https://github.com/Pudon/weapp-qrcode-base64
在項目中引入 weapp-qrcode.js 文件
js
const app = getApp(); const QR = require('../../lib/weapp-qrcode.js'); // 引入 weapp-qrcode
Page({ /** * 頁面的初始數據 */ data: { QrCodeURL:'', // 二維碼圖片路徑
}, // 二維碼
drawImg: function (){ let that = this, params = "https://www.baidu.com/"; // 二維碼參數
var imgData = QR.drawImg(params, { typeNumber: 4, // 密度
errorCorrectLevel: 'L', // 糾錯等級
size: 800, // 白色邊框
}) this.setData({ qrcodeURL: imgData }) }, })
html
<view style="text-align:center;">
<image style="width:500rpx;height:500rpx;" src="{{ qrcodeURL }}" ></image>
</view>