uni-app中生成二维码

目录

1. uni-app插件介绍

1.1 下载方式

1.1.1 npm下载

 1.1.2 下载插件并导入HBuilderX

2.使用

2.1 下载后 在项目的components下

2.2 页面中使用

2.3 展示

​编辑


最近,项目做收款的时候,需要微信的Native支付(通俗一些就是扫码微信支付),需要生成不同的二维码。

不懂什么是Native支付的,查看链接  Native支付

1. uni-app插件介绍

二维码生成器二维码生成 可设置二维码logoicon-default.png?t=N7T8https://ext.dcloud.net.cn/plugin?id=39

1.1 下载方式

1.1.1 npm下载

npm i tki-qrcode

 1.1.2 下载插件并导入HBuilderX

注意:这个插件是vue2开发的,在导入vue3项目的时候会提示如下的错误,我在使用中正常,并没发现异常。

2.使用

2.1 下载后 在项目的components下

2.2 页面中使用

<template>
  <view class="container">
    <!-- 二维码展示区域 -->
    <view class="qrcode-wrap">
      <view class="qrimg">
        <tki-qrcode
          ref="qrcode"
          :cid="qrform.cid"
          :val="qrform.val"
          :size="qrform.size"
          :unit="qrform.unit"
          :background="qrform.background"
          :foreground="qrform.foreground"
          :pdground="qrform.pdground"
          :icon="qrform.icon"
          :iconSize="qrform.iconsize"
          :lv="qrform.lv"
          :onval="qrform.onval"
          :loadMake="qrform.loadMake"
          :usingComponents="qrform.usingComponents"
          :showLoading="qrform.showLoading"
          :loadingText="qrform.loadingText"
          @result="qrR"
        />
      </view>
    </view>
    <!-- 二维码配置区域 -->
    <view class="qrcode-setting">
      <label> 二维码内容 </label>
      <input type="text" v-model="qrform.val" />
    </view>
  </view>
</template>

<script setup lang="ts">
import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
import { reactive } from 'vue';

const qrform = reactive({
  cid: 'tki-qrcode-canvas', // 二维码唯一ID
  val: 'https://blog.csdn.net/weixin_53630395?type=lately', // 要生成的二维码值
  size: 400, // 二维码大小
  unit: 'upx', // 单位
  background: '#000000', // 背景色
  foreground: '#ffffff', // 前景色
  pdground: '#ffffff', // 角标色
  icon: '', // 二维码图标 二维码中心的icon图标
  iconsize: 60, // 二维码中心icon图标大小
  lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  onval: true, // val值变化时是否自动重新生成二维码
  loadMake: true, // 组件加载完成后是否自动生成二维码
  src: '', // 二维码生成后的图片地址或base64
  usingComponents: false, // 是否使用了自定义组件模式
  showLoading: true, // 是否显示loading
  loadingText: '二维码生成中', // loading展示文案
});


const qrR = (res:any) => {
	console.log(res);
}
</script>

<style scoped lang="scss">
.container {
  .qrcode-wrap {
    box-sizing: border-box;
    padding: 20rpx 40rpx;
    display: flex;
    justify-content: center;
    height: 500rpx;

    .tki-qrcode {
      padding: 30rpx;
      height: 400rpx;
      border-radius: 16rpx;
      background-color: #e8de61;
    }
  }

  .qrcode-setting {
    margin-top: 30rpx;
    padding: 10rpx 20rpx;
    box-sizing: border-box;

    input {
      border: 1rpx solid #e9f0fd;
      height: 64rpx;
      line-height: 64rpx;
      text-indent: 12rpx;
      border-radius: 12rpx;
    }
  }
}
</style>

2.3 展示

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值