二维码生成&点击按钮展示二维码

使用HBuider
1.先安装插件
(地址 :  https://ext.dcloud.net.cn/plugin?id=1287

这里直接就安装到了uni-modules里面了

2、引入

import uQRCode from ‘@/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue’

3、代码实现
 

<template>
   <view>
<!-- 渲染数据 -->
		<view class="u-demo-block__content wrap" v-for="item in filteredList" :key="item.id">
			<u-row class="contentbox">
				<u-col span="12" class="action-item">
					<view><text class="info">xxx:</text>{{item.outbound.udeptName}}</view>
				  <view class="button">
				 <!-- 点击二维码出来 @click="click(item)" -->
						<button class="button-item" type="primary" @click="click(item)">二维码显示</button>
					</view>
				</u-col>
			</u-row>
		</view>
		<!-- 二维码 -->
		<view>
		<!-- 弹框 -->
			<uni-popup ref="popup" background-color="#fff">
				<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
					<uqrcode ref="uQRCode" :mode="mode" :value="text" :size="size" :margin="margin" canvasId="item.id"
						background-color="backgroundColor" :foreground-color="foregroundColor" :typeNumber="typeNumber"
						:fileType="fileType" />
				  </view>
			</uni-popup>
		</view>
	</view>
</template>
<script>
	import {receive} from '@/api/xxx/index'  
	import uQRCode from '@/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue'
	export default {
		data() {
			return {
				mode: 'canvas',//也可以是view
				text: 'test',//也可以写网址,直接生成对应的二维码
				size: 140,
				margin: 10,
				backgroundColor: '#FFFFFF',
				foregroundColor: '#000000',
				//errorCorrectLevel: uQRCode.errorCorrectLevel.H,  
				typeNumber: -1,
				fileType: 'png',
				defaultErrorCorrectLevel: uQRCode.errorCorrectLevel,
				type: 'center', //弹框在中央
			}
		},
		methods: {
		 // 请求数据
			getReceive() {
				receive().then(res => {
					this.receiveList = res.rows;
				}).catch((error) => {})
			},
			//点击二维码出来
			click(item) {
				console.log(item);
				//这里把数据的id赋值给text,绑定到上面,这样点击就是对应的二维码
				this.text = item.outbound.id;
				console.log(this.text);
				this.$refs.popup.open("center")  //这里是弹框在最中央
			}
	}
</script>
<style>
	.example-body {
		background-color: #fff;
		padding: 10px 0;
	}

	.button-text {
		color: #fff;
		font-size: 12px;
	}

	.popup-content {
		@include flex;
		align-items: center;
		justify-content: center;
		padding: 30px;
		height: 180px;
		width: 180px;
		background-color: #fff;
	}
</style>

4.开发中使用

弹框用到了uni-app提供的uni-popup弹框,把二维码放到内容那块,替换即可

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沙尘暴炒饭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值