vue环境中生成二维码

<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>

posted @ 2018-01-19 13:12  superAnny  阅读(7313)  评论(1编辑  收藏  举报