首页 > 解决方案 > NativeScript-vue 条码创建

问题描述

嗨,我想问一下是否有在 nativescript-vue 中创建条形码,有很多创建条形码的 vue js 示例,但我不具备翻译或转换代码的能力。有没有人可以给我一个在 nativescript-vue 上创建条形码的例子?谢谢你。

标签: nativescript-vue

解决方案


您可以使用nativescript-qr-generator& nativescript-base-64-manager

仅当base-64您要将 QR 码转换为 base-64 时。

将其导入您的模板:

import { QrGenerator } from "nativescript-qr-generator";
import { Base64Manager } from "nativescript-base-64-manager";

你需要一个数据属性generatedQR: null,然后你需要一个方法来生成 QR。所以生成了二维码,然后你的代码值被转换为base64值。您还可以将任何数据附加到结果中,例如 url:new QrGenerator().generate("url/" + _Base64Manager.btoa(this.code)

 generateQR() {
      const _Base64Manager = new Base64Manager();
      const result = new QrGenerator().generate( _Base64Manager.btoa(this.code),
        {
          color: "#your_color",
          backgroundColor: "#your_color"
        }
      );
      this.generatedQR = new ImageSource(result);
    }

在模板中,您将拥有像图像一样的 QR 码:

<Image :src="generatedQR" row="4" imageFit="aspectFill"/>

推荐阅读