安装:
npm install --save qrcode
使用:
<template>
<div id="app">
<canvas id="canvas" />
</div>
</template>
<script>
export default {
name: 'App',
mounted(){
this,init()
},
method:{
init(){
const QRCode = require('qrcode')
const opts = {
errorCorrectionLevel: 'H',
type: 'image/png',
quality: 0.3,
margin: 0,
width: 80,
height: 80,
text: '二维码内容',
color: {
dark: '#333333',
light: '#fff'
}
}
QRCode.toCanvas(
document.getElementById('canvas'),
'扫描之后出来的内容',
opts,
function(error) {
console.log(error)
}
)
},
}
}
</script>