vue使用qrcodejs2生成二维码

安装插件
npm i qrcodejs2 -S
使用页面
<template>
<div id="qrcode" style="width:200px;height:200px;margin-top:30px" ref="qrCodeUrl"></div>
<template>

<script>
	import QRCode from 'qrcodejs2'  //引入qrcodejs2
	
	mounted () {
    
    
	//vue需要在mounted调用  不然获取不到dom   如果是弹框  在弹框显示的时候调用
    this.creatQrCode();
  	},
	mothods:{
    
    
		getSettleQrcode(){
    
    
      //如果是在弹框里面生成  需要生成之前清空dom
      const codeHtml = document.getElementById("qrcode");
      codeHtml.innerHTML = "";
      var qrcode= new QRCode(this.$refs.qrCodeUrl, {
    
    
            text: 'www.baidu.com', // 需要转换为二维码的内容
            width: 100,
            height: 100,
            colorDark: '#000000',
            colorLight: '#ffffff',
            correctLevel: QRCode.CorrectLevel.H
        	})
    	}
	},
<script>

おすすめ

転載: blog.csdn.net/YuT_ian/article/details/116228160