vue环境中生成二维码
代码如下:
引入qrcode--------npm install qrcode
<template>
<div>
<div id=‘code‘></div>
<canvas id="canvas"></canvas>
</div>
</template>
<script>
import Vue from ‘vue‘
import QRCode from ‘qrcode‘
Vue.use(QRCode)
export default {
data() {
return {
codes: ‘‘
}
},
methods: {
useqrcode() {
var canvas = document.getElementById(‘canvas‘)
QRCode.toCanvas(canvas, ‘http://www.baidu.com‘, function(error) {
if (error) console.error(error)
console.log(‘success!‘);
})
}
},
mounted() {
this.useqrcode();
}
}
</script>
<style>
#canvas {
width: 200px !important;
height: 200px !important;
}
</style> 相关推荐
hell0kitty 2019-11-30
bertZuo 2019-07-01
JamesNan 2019-06-29
zhaidpjava 2019-06-26
83457317 2012-09-27
mayflowers 2019-06-20
梦秋雨 2016-10-26
jsjcaowei 2018-01-31
asanlr 2015-12-27
xiyanwushi 2017-01-07
BlueBuleSky 2017-07-11
taku 2019-04-26
89443062 2016-04-03
87941037 2019-04-22