Skip to content

Commit

Permalink
fix: errorCorrectLevel error.
Browse files Browse the repository at this point in the history
  • Loading branch information
scopewu committed Oct 19, 2021
1 parent 4eb182e commit 56af7fd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions example/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<div class="col-sm-10">
<select v-model="level" class="form-control">
<option value="L">L</option>
<option value="Q">Q</option>
<option value="M">M</option>
<option value="Q">Q</option>
<option value="H">H</option>
</select>
</div>
Expand Down Expand Up @@ -120,7 +120,7 @@ import QrcodeVue from '../src'
const value = ref('https://example.com')
const size = ref(100)
const level = ref<'L' | 'Q' | 'M' | 'H'>('L')
const level = ref<'L' | 'M' | 'Q' | 'H'>('L')
const background = ref('#ffffff')
const foreground = ref('#000000')
const renderAs = ref<'canvas' | 'svg'>('svg')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qrcode.vue",
"version": "3.3.2",
"version": "3.3.3",
"description": "A Vue.js component to generate QRCode.",
"main": "dist/qrcode.vue.cjs.js",
"module": "dist/qrcode.vue.esm.js",
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineComponent, h, onMounted, onUpdated, PropType, ref } from 'vue'
import QR, { ErrorCorrectLevel } from 'qr.js'
import QR from 'qr.js/lib/QRCode.js'
import ErrorCorrectLevel from 'qr.js/lib/ErrorCorrectLevel.js'

type Modules = boolean[][]
type Level = 'L' | 'M' | 'Q' | 'H'
Expand All @@ -20,7 +21,11 @@ function QRCode(data: string, level: Level): { modules: Modules } {
const errorCorrectLevel = ErrorCorrectLevel[level]

// We'll use type===-1 to force QRCode to automatically pick the best type
return QR(toUTF8String(data), { typeNumber: -1, errorCorrectLevel })
const qrcode = new QR(-1, errorCorrectLevel)
qrcode.addData(toUTF8String(data))
qrcode.make()

return qrcode
}

function validErrorCorrectLevel(level: string): boolean {
Expand Down
3 changes: 2 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module 'qr.js'
declare module 'qr.js/lib/QRCode.js'
declare module 'qr.js/lib/ErrorCorrectLevel.js'

// shims-vue.d.ts
declare module '*.vue' {
Expand Down

0 comments on commit 56af7fd

Please sign in to comment.