uniapp中H5网页和打包app分别生成二维码

一、h5网页中生成二维码业务
引入“qrcodejs2.js":npm install qrcodejs2;
<template>
	<view>
		<view id="guestQrcode" style="text-align: center;"></view>
	</view>
</template>
<script>
	import QRCode from "qrcodejs2";
	export default {
		data() {
			return {
			}
		},
		mounted() {
			let proportionUpdate = document.getElementById('guestQrcode');
			if (proportionUpdate) {
				proportionUpdate.innerHTML = ""
			}
			// document.getElementById('guestQrcode').innerHTML="";
			this.$nextTick(() => {
				setTimeout(() => {
					var qrcode = new QRCode(document.getElementById("guestQrcode"), {
						width: 223,
						height: 223
					});
					qrcode.clear(); // 清除代码
					qrcode.makeCode("要生成二维码的数据"); // 生成另外一个二维码
				}, 500)
			})
		},
		methods: {}
	}
</script>
<style lang="scss" scoped>
</style>

二、app中生成二维码业务

对于uniapp开发,可以去DCloud插件市场找各种各样的插件,在这里分享一款制作二维码的插件二维码生成器
在这里插入图片描述
首先使用HBuildreX导入插件,导入成功之后,项目目录下面将会多出一个ay-qrcode组件,然后在对应需要用到的界面使用即可。

<template>
	<view>
		<ayQrcode ref="qrcode" :modal="modal_qr"  @hideQrcode="hideQrcode"  :url="url" :height="150" :width="150"/>
	</view>
</template>

<script>
	import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue"
	export default {
		components: {
			ayQrcode
		},
		data() {
			return {
				modal_qr :false,
				url: '' // 要生成的二维码值
			}
		},
		onLoad() {
			//一加载生成二维码
			this.showQrcode() 
		},
		methods: {
			showQrcode(){
				this.modal_qr = true;
				this.url = "要生成二维码的数据"
				setTimeout(function() {
					_this.$refs.qrcode.crtQrCode()
				}, 50)
			},
			hideQrcode(){
				this.modal_qr = false;
			}
		}
	}
</script>

<style scoped lang="scss">
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值