npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yang-gang/weapp-qrcode

v1.0.3

Published

generate qrcode in weapp

Downloads

4

Readme

weapp-qrcode

npm version change-log

weapp.qrcode.js 在 微信小程序 中,快速生成二维码,只支持微信2.9.0之后的新版本

Usage

先在 wxml 文件中,创建绘制的 canvas,并定义好 width, height, id

[注意:]如果是在组件中使用,必须设置 _this 选项,则必须传入当前组件 this

<canvas type="2d" id="myQrcode" style="width:300px;height:400px;"></canvas>

直接引入 js 文件,使用 drawQrcode() 绘制二维码。!!!在 调用 drawQrcode() 方法之前,一定要确保可以获取到 canvas context

在 v0.6.0 版本构建出多个文件,详情移步Build Files说明

// 也可以将 dist 目录下,weapp.qrcode.esm.js 复制到项目目录中直接引用使用
import drawQrcode from '@yang-gang/weapp-qrcode/dist/weapp.qrcode.esm.js'

drawQrcode({
  width: 200,
  height: 200,
  id: '#myQrcode',
  // ctx: wx.createSelectorQuery(),
  text: 'https://github.com/yingye',
  // v1.0.0+版本支持在二维码上绘制图片
  image: {
    imageResource: '../../images/icon.png',
    dx: 70,
    dy: 70,
    dWidth: 60,
    dHeight: 60
  }
})

如果项目使用了 wepy 框架,可直接安装 @yang-gang/weapp-qrcode npm包。

npm install @yang-gang/weapp-qrcode --save
import drawQrcode from '@yang-gang/weapp-qrcode/dist/weapp.qrcode.esm.js'

drawQrcode({
  width: 200,
  height: 200,
  id: 'myQrcode',
  text: 'https://github.com/yingye'
})

DEMO

更多 demo 可以参考 examples目录,示例包含原生语法及WePY、mpvue、Taro框架。

API

drawQrcode([options])

options

Type: Object

| 参数 | 说明 | 示例| | ------ | ------ | ------ | | width | 必须,二维码宽度,与canvaswidth保持一致 | 200 | | height | 必须,二维码高度,与canvasheight保持一致 | 200 | | id | 非必须,canvas元素的id | '#myQrcode' | | ctx | 非必须,绘图上下文,可通过 wx.createSelectorQuery() 获取,v2.9.0+版本支持 | 'wx.createSelectorQuery()' | | _this | 非必须,在自定义组件中,如果使用id获取canvas实例,则必须传入当前组件this | componentInstance | | text | 必须,二维码内容 | 'https://github.com/yingye' | | typeNumber | 非必须,二维码的计算模式,默认值-1 | 8 | | correctLevel | 非必须,二维码纠错级别,默认值为高级,取值:{ L: 1, M: 0, Q: 3, H: 2 } | 1 | | drawBg | 非必须,是否绘制画布背景,默认值为false,取值:true OR false | false | | bgColor | 非必须,绘制画布背景的颜色,默认值为'#ffffff' | #ffffff | | scale | 非必须,可设置缩放倍数,数字越大图片越大,越清晰 | 默认是手机的像素比Dpr | | correctLevel | 非必须,二维码纠错级别,默认值为高级,取值:{ L: 1, M: 0, Q: 3, H: 2 } | 1 | | background | 非必须,二维码背景颜色,默认值白色 | '#ffffff' | | foreground | 非必须,二维码前景色,默认值黑色 | '#000000' | | callback | 非必须,绘制完成后的回调函数,v0.8.0+版本支持。安卓手机兼容性问题,可通过自行设置计时器来解决,更多可以参考 issue #18 | function (ctx, canvas) { console.log('e', e) } | | x | 非必须,二维码绘制的 x 轴起始位置,默认值0,v1.0.0+版本支持 | 100 | | y | 非必须,二维码绘制的 y 轴起始位置,默认值0,v1.0.0+版本支持 | 100 | | image | 非必须,在 canvas 上绘制图片,层级高于二维码,v1.0.0+版本支持,更多可参考drawImage | { imageResource: '', dx: 0, dy: 0, dWidth: 100, dHeight: 100 } |

位置信息可以参见下图:

TIPS

weapp.qrcode.js 二维码生成部分借鉴了 jquery-qrcode 源码,可以参考 jquery-qrcode