美文网首页
vue qrcode(插件) 二维码实例

vue qrcode(插件) 二维码实例

作者: 啊布多 | 来源:发表于2021-09-10 11:05 被阅读0次

导入qrcode插件

npm install qrcode2 --save

二维器生成器

import QRCode from 'qrcodejs2'

export function qrcode(id, code, w, h) {
new QRCode(id, {
width: w || 124,
height: h || 124,
text: code // 二维码内容
// render: 'canvas' , // 设置渲染方式(有两种方式 table和canvas,默认是canvas)
// background: '#f0f', // 背景色
// foreground: '#ff0' // 前景色
})
}

vue实现

<template>
<div id="qrcode" />
</template>
<script>
import { qrcode } from '@/utils/qrcode'
export default {
// eslint-disable-next-line vue/no-unused-components
// components: { },
data: function() {
return {
temp: {
code: '123456',
qrcode: undefined
}
}
},
created() {
this.$nextTick(function() {
this.qrcode()
})
},
methods: {
// 生成二维码
qrcode() {
qrcode('qrcode', this.temp.code, 100, 100)
}
}
}
</script>

相关文章

网友评论

      本文标题:vue qrcode(插件) 二维码实例

      本文链接:https://www.haomeiwen.com/subject/kffpwltx.html