Uniapp verwendet das Vue2-Framework, um QR-Code zu generieren

 1. QR-Code-Plugin generieren
 

npm install qrcodejs2 --save

Obiger Code:
 

<template>
		<view>
	<view class="page" >
       <div	 id="qrCode" ref="qrCodeDiv" ></div>
	 
	</view>
	  <view  class="page">核销码:{
   
   {verificationCode}}</view>
	</view>
</template>

<script>
 import QRCode from 'qrcodejs2'
	export default {
		name: "qrCode",
		data() {
			return {
				orderNo:"",
				verificationCode:'',
				qrCodeData:''
			}
		},
	
		onLoad(options) {
		console.log(options.orderNo);
		this.orderNo=options.orderNo
		this.verificationCode=options.verificationCode
		},
		created () { // 初始化以后
		        let _self = this
		        _self.$nextTick(() => { // 调用必须写在 $nextTick 里
		          _self.bindQRCode()
		        })
		      },
		methods: {
			  bindQRCode () {
				   this.qrCodeData=this.orderNo//订单编号作为二维码信息
			          new QRCode(this.$refs.qrCodeDiv, {
			            text: this.qrCodeData,  // 此处为变量,要生成二维码的地址
			            width: 150, // 二维码的宽高
			            height: 150,	
			            colorDark: '#333333',//二维码颜色
			            colorLight: '#ffffff',//二维码背景色
			            correctLevel: QRCode.CorrectLevel.L //容错率。 L/M/H
			          })
			},
			
			  
		}
	}
</script>
<style lang="scss" scoped>
	page {
		background-color: #fff;
	}
	.page{
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 30rpx;
	}

	
</style>

Darstellungen

Guess you like

Origin blog.csdn.net/qq_46376192/article/details/132832082