vue生成自定义二维码样式

2 篇文章 0 订阅

一:npm安装包

npm install qrcanvas -S

二:组件引入

import { qrcanvas } from ‘qrcanvas’;

三: 使用

3.1:自定义颜色

    const canvas = qrcanvas({
      cellSize: 8,
      correctLevel: 'H',
      data: 'https://www.baidu.com',
      foreground: [
        // foreground color
        { style: '#55a' },
        // outer squares of the positioner
        { row: 0, rows: 7, col: 0, cols: 7, style: '#c33' },
        { row: -7, rows: 7, col: 0, cols: 7, style: '#c33' },
        { row: 0, rows: 7, col: -7, cols: 7, style: '#c33' },
        // inner squares of the positioner
        { row: 2, rows: 3, col: 2, cols: 3, style: '#621' },
        { row: -5, rows: 3, col: 2, cols: 3, style: '#621' },
        { row: 2, rows: 3, col: -5, cols: 3, style: '#621' },
      ]
    });
    let id= document.getElementById('id');
    id.appendChild(canvas);

在这里插入图片描述

3.2自定义logo

自定义为文字

 const canvas = qrcanvas({
      cellSize: 8,
      correctLevel: 'H',
      data: 'https://www.baidu.com',
      foreground: [
        // foreground color
        { style: '#55a' },
        // outer squares of the positioner
        { row: 0, rows: 7, col: 0, cols: 7, style: '#c33' },
        { row: -7, rows: 7, col: 0, cols: 7, style: '#c33' },
        { row: 0, rows: 7, col: -7, cols: 7, style: '#c33' },
        // inner squares of the positioner
        { row: 2, rows: 3, col: 2, cols: 3, style: '#621' },
        { row: -5, rows: 3, col: 2, cols: 3, style: '#621' },
        { row: 2, rows: 3, col: -5, cols: 3, style: '#621' },
      ],
      logo: {
        text: 'QRCanvas',
        options: {
          color: 'dodgerblue',
        },
      }
    });
    let docum = document.getElementById('logins')
    docum.appendChild(canvas);

在这里插入图片描述

自定义图片

const image = new Image();
image.src = 'https://user-images.githubusercontent.com/3139113/38300650-ed2c25c4-382f-11e8-9792-d46987eb17d1.png';
image.onload = () => {
  const canvas = qrcanvas.qrcanvas({
    cellSize: 8,
    correctLevel: 'H',
    data: 'hello, world',
    logo: {
      image,
    },
  });
  container.appendChild(canvas);
};

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值