![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
qrcode-pure
Advanced tools
二维码编码与解码。 核心源码来自项目qrcode,但qrcode使用的是jquery封装,
qrcode-pure
在此将两个功能拆分了出来,单纯的作为两个函数调用。
# 安装依赖
npm i install --save qrcode-pure
需要传入一个canvas DOM
调用qrdecode
解码后返回的值为一个对象。
|参数|备注|
|-|:-:|-|
|text|解码后的值|
|canvas|解析的canvasDOM|
可参考项目qrcode内的参数。
调用qrencode
编码后返回的值为一个对象。
|参数|备注|
|-|:-:|-|
|canvas|编码后的的canvasDOM|
在项目中使用:(解析单张二维码)
<!-- template -->
<input type="file" @change="handleChange">
<canvas ref="decode-canvas">
<button @click="decode">点击解码</button>
// 引入解码函数
// script
import qrdecode from 'qrcode-pure/lib/qrdecode'
// methods
handleChange(e) {
var canvas = this.$refs['decode-canvas'],
ctx = canvas.getContext('2d'),
file = e.target.files[0],
reader = new FileReader()
reader.onload = function(e) {
var img = new Image()
img.onload = function() {
canvas.width = img.width
canvas.height = img.height
ctx.drawImage(img, 0, 0)
}
img.src = e.target.result
}
file && reader.readAsDataURL(file)
}
// 调用解码函数
// 传入一个canvas,内容为二维码
// 如果是上传的图片,需要调用canvas的drawImage方法,生成canvas
function decode(){
let result = qrdecode(this.$refs['decode-canvas')
// result返回值为解码后的值
console.log('result', result)
}
在项目中使用:(解析多张二维码)
<!-- template -->
<input type="file" multiple @change="handleChange">
// 引入解码函数
// script
import qrdecode from 'qrcode-pure/lib/qrdecode'
// methods
handleChange(e) {
if (e.target.files.length === 0) return
Object.values(e.target.files).forEach(v => {
let canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
reader = new FileReader()
reader.onload = function(e) {
var img = new Image()
img.onload = function() {
canvas.width = img.width
canvas.height = img.height
ctx.drawImage(img, 0, 0)
// 调用结果 result 为对象,具体参数参考 文档 => decode 解码
let result = qrdecode(canvas)
}
img.src = e.target.result
}
v && reader.readAsDataURL(v)
})
}
在项目中使用:(vue单文件组件为例)
<!-- template -->
<el-button @click="encode" type="primary" size="mini" class="m-l_2">编码</el-button>
// 引入解码函数
// script
import qrencode from 'qrcode-pure/lib/qrencode'
// methods
encode() {
// 调用 qrencode 编码函数,可接受一个对象参数
// 参数具体内容请参考项目[qrcode](https://github.com/nuintun/qrcode),在此不再赘述。
// 返回值为一个对象
// 其中canvas属性为编码后二维码的canvas DOM
let result = qrencode({ text: 'https://pkjy.github.io' })
}
注:本项目处理建设阶段,代码变化比较频繁。
FAQs
qrcode encode and decode
The npm package qrcode-pure receives a total of 1 weekly downloads. As such, qrcode-pure popularity was classified as not popular.
We found that qrcode-pure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.