qrcode

生成二维码模块

TIP

<image ref="img" class="image" autoBitmapRecycle="false"></image>

用于显示图片的image标签,要加上autoBitmapRecycle="false"属性,禁用自动回收,要不应用推到后台后,生成的二维码会被回收。

API

gen

生成二维码

gen(ref, options, callback)

  • @ref {Object}:二维码生成后,到指定image中显示
  • @options {Object}:选项参数
    • content {string}:用于生成二维码的内容
    • type {string}:内容类型,如果是base64,则值为base64,否则当普通字符串处理
    • size {int}:图片大小
    • color {string}:二维码颜色
    • logo {string}:二维码logo URL地址
  • @callback {Function}:执行完该操作后的回调函数。回调函数将收到一个Response对象
    • result {string}:success表示生码成功,cancel表示失败

Demo

const qrcode = weex.requireModule('qrcode');
const modal = weex.requireModule('modal');

qrcode.gen(this.$refs.img, {
    content: "bG1zcGF5LmNvbQ==",
    size: 200,
    type: "base64"
}, (e) => {
    if(e.result === 'cancel') {
        modal.toast({
            message: "gen qrcode failed.",
            gravity: "bottom",
            duration: 1
        });
    }
});