关键词搜索

源码搜索 ×
×

uni-app使用canvas绘制二维码

发布2022-06-26浏览545次

详情内容

在这里插入图片描述

1. 插件选型

uqrCode

点击安装即可
https://ext.dcloud.net.cn/search?q=uqrCode
在这里插入图片描述

2. 页面部分

template:

	
				<view class="canvas-qrcode-box" style="align-self: center;">
					<canvas id="qrcode" canvas-id="qrcode" style="width: 170px;height: 170px;align-self: center;" />
				</view>
    3.事件部分
    <script>
    	var system = uni.getSystemInfoSync();
    	import uQRCode from '@/uni_modules/Sansnn-uQRCode/components/uqrcode/common/uqrcode.js'
    	export default {
    		data() {
    			return {
    				vlogId: "",
    				// screenHeight: system.screenHeight,
    				screenHeight: system.safeArea.bottom,
    				statusBarHeight: system.statusBarHeight
    			}
    		},
    		onReady() {
    			var vlogId = this.vlogId;
    			var content = {
    				type: "vlog",
    				content: vlogId
    			};
    			var contentStr = JSON.stringify(content);
    		    uQRCode.make({
    		        canvasId: 'qrcode',
    		        componentInstance: this,
    		        size: 170,
    		        margin: 10,
    		        text: contentStr,
    		        backgroundColor: '#ffffff',
    		        foregroundColor: '#0f0827',
    		        fileType: 'png',
    		        errorCorrectLevel: uQRCode.errorCorrectLevel.H
    		    })
    		    .then(res => {
    		    })
    		  },
    		onLoad(params) {
    			var vlogId = params.vlogId;
    			this.vlogId = vlogId;
    		},
    		methods: {
    			close() {
    				uni.navigateBack({
    					delta: 1,
    					animationType: "slide-out-bottom"
    				})
    			},
    		}
    	}
    </script>
    
    
    
    
      5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50

    相关技术文章

    点击QQ咨询
    开通会员
    返回顶部
    ×
    微信扫码支付
    微信扫码支付
    确定支付下载
    请使用微信描二维码支付
    ×

    提示信息

    ×

    选择支付方式

    • 微信支付
    • 支付宝付款
    确定支付下载