1.首先安装qrcode
npm install --save qrcodejs2
2.引用
import QRCode from 'qrcodejs2'
3.使用
<div class="qrcode" ref="qrCodeUrl"></div>
<script>
methods: {
creatQrCode() {
var qrcode = new QRCode(this.$refs.qrCodeUrl, {
text: 'xxxx', // 需要转换为二维码的内容
width: 100,
height: 100,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
})
},
},
mounted() {
this.creatQrCode();
},
</script>
4.添加样式美化
.qrcode{
display: inline-block;
img {
width: 132px;
height: 132px;
background-color: #fff; //设置白色背景色
padding: 6px; // 利用padding的特性,挤出白边
box-sizing: border-box;
}
}
本文介绍了如何通过qrcodejs2库在前端创建二维码,包括安装步骤、代码引用和使用方法,还提供了美化样式示例。适合前端开发者学习和实践基础二维码生成技术。
&spm=1001.2101.3001.5002&articleId=123480588&d=1&t=3&u=98aa7de391e647799eab6d6184e6d397)
2万+

被折叠的 条评论
为什么被折叠?



