qrcode
引入qrcode
"qrcode": "^1.4.4",
使用
//直接转换
const url = await QRCode.toDataURL(code)
//或者
const createQrcode = (content) => {
const codeBase64: any[] = []
content?.forEach((item, index) => {
QRCode.toString(content, { type: 'svg' }, function (err, string) {
if (err) throw err
// data:image/svg+xml;charset=utf-8,
// packageCodes
// const utf8Bytes = new TextEncoder().encode(string)
const utf8Bytes = encodeUTF8(string)
const base64Svg = 'data:image/svg+xml;base64,' + base64_encode(String.fromCharCode.apply(null, utf8Bytes))
codeBase64[index] = base64Svg
})
})
setPackageCodesBase64(codeBase64)
}