uni-app 生成二维码 简单demo

1.首先引入插件

import uQRCode from "@/components/uqrcode/uqrcode.js"

插件代码下载地址如下:
https://github.com/Sansnn/uQRCode

  1. 需要定义的数据
data() {
		return {
			qrcodeText: '',
			qrcodeSize: 100,
			qrcodeSrc: '',
			name:','
		}
	},
  1. 方法
methods: {
			make() {
				uni.showLoading({
					title: '生成中...',
					mask: true
				})
				uQRCode.make({
					canvasId: 'qrcode',
					text: this.qrcodeText,
					size: this.qrcodeSize,
					margin: 10,
					success: res => {
						this.qrcodeSrc = res
					},
					complete: () => {
						uni.hideLoading()
					}
				})
			},
}
  1. 在onLoad中调用该方法以及传参
onLoad(e) {
			//console.log(e)
			this.qrcodeText=e.id
			this.name=e.wzmc
			this.sblx=e.sblx
			this.sbbm=e.sbbm
			this.make()
},

5.前端代码

<view class="box_tr">
	<view class="canvas tr_left td">
		<canvas canvas-id="qrcode" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`}" />
	</view>
</view>

6.这是我的最后生成效果如下:
在这里插入图片描述
7.css样式代码:

<style>
	page {
		background-color: #f0f0f0;
	}
	
	.gys{
		padding: 20rpx 0rpx 20rpx 0rpx;
	}

	.box_table{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 50rpx;
	}
	.box_tr{
		float: left;
		width: 90%;
		height: 100%;
		display: flex;
		flex-direction: row;
		justify-content: center;
		border: 1px solid #333333;
		margin-top: -1px;
	}
	.td{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 50%;
		height: 100%;
		padding: 15rpx 20rpx 15rpx 20rpx;
		border-right: 1px solid #333333;
		font-size: 30rpx;
		color: #222222;
		margin-right: -1px;
		
	}
	.tr_left{
		float: left;
	}
	.tr_right{
		float: left;
	}
</style>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值