vue 生成 二维码 qrCode 插件 使用 方法
发布日期:2021-05-08 23:40:50 浏览次数:19 分类:技术文章

本文共 837 字,大约阅读时间需要 2 分钟。

首先安装方法:(--save 参数会改变package.json 推荐使用 下次直接install就行了)

 
npm install --save qrcode

 然后项目使用:

import QRCode from 'qrcode'

 

 

然后使用方法:

html 使用

 

// index.js -> bundle.jsvar QRCode = require('qrcode')var canvas = document.getElementById('canvas') QRCode.toCanvas(canvas, '二维码内容xxxxxx', function (error) {  if (error) console.error(error)  console.log('success!');})

 

NodeJS

var QRCode = require('qrcode') QRCode.toDataURL('二维码内容xxxxxx!', function (err, url) { console.log(url) })

 

ES6/ES7

1.异步方式

import QRCode from 'qrcode' // With promisesQRCode.toDataURL('二维码内容xxxxxx!') .then(url => { console.log(url) }) .catch(err => { console.error(err) })

 

2.同步方式

// With async/await
let text = 'xxxxxxxx';const generateQR = async text => {  try {    console.log(await QRCode.toDataURL(text))  } catch (err) {    console.error(err)  }}
 

 

 

 

 

 

 

 

 

上一篇:【微信支付】小微商户进件 接口分析与源码实现
下一篇:mybatis 一对多查询 集合创建空对象的问题

发表评论

最新留言

很好
[***.229.124.182]2025年04月28日 01时25分21秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章