1.0 安装:
cnpm install --save qrcodejs2
2.0 在组建中引入:
import QRCode from 'qrcodejs2'
3.0 使用:
3.1.0 页面中直接使用:
<template>
<div>
<div id="qrcode"></div>
</div>
</template>
<script>
import QRCode from 'qrcodejs2'
export default {
name : 'test',
mounted () {
this.qrcode();
},
methods: {
qrcode() {
let qrcode = new QRCode('qrcode', {
width: 132,
height: 132,
text: 'https://www.baidu.com',
colorDark : "#000",
colorLight : "#fff",
})
},
}
}
</script>
<style scoped lang='scss'>
#qrcode {
display: inline-block;
img {
width: 132px;
height: 132px;
background-color: #fff; //设置白色背景色
padding: 6px; // 利用padding的特性,挤出白边
}
}
</style>
3.2.0 弹框中使用:
<template>
<div>
<p @click="getinvite()">点击出现弹框</p>
// 弹框
<div v-if="isinvite==true">
<div class="qrcode" ref="qrcodeContainer"></div>
</div>
</div>
</template>
<script>
import QRCode from 'qrcodejs2'
export default {
data(){
return {
isinvite:false
}
},
methods: {
getinvite(type) {
this.isinvite = !this.isinvite;
if (type == 0) {
this.showQRCode();
}
},
showQRCode(){
this.$nextTick(()=>{
var qrcode = new QRCode(this.$refs.qrcodeContainer, {
text: 'https://wallimn.iteye.com',
width: 100,
height: 100,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
})
})
},
}
}
</script>
<style scoped lang="scss">
.qrcode {
width: 180px;
height: 180px;
display: block;
margin: 0 auto;
img {
width: 132px;
height: 132px;
background-color: #fff; //设置白色背景色
padding: 6px; // 利用padding的特性,挤出白边
}
}
</style>
4.0 清楚
qrcode.clear();