Created
February 27, 2020 12:54
-
-
Save tohagan/a6c035f4b0c77a1d3085f80efd6cc6cd to your computer and use it in GitHub Desktop.
Fast SVG QR Code for Vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fast and does not need width/height (CSS sizing is more powerful) | |
// https://github.com/udwarf/qrcode-compact-svg | |
import { QRCode as QRCodeSvg } from "./qrcode-compact-svg"; | |
export default { | |
name: "qr-code", | |
props: { | |
content: { type: String, required: true }, // URL or text to encode | |
padding: { type: Number, default: 1 }, // 0 .. 1 padding | |
color: { type: String, default: "black" }, // Foreground color | |
background: { type: String, default: "white" }, // Background color | |
// https://www.qrcode.com/en/about/error_correction.html | |
ecl: { type: String, default: "L" }, // QR Code Error Correction Level (L 7%, M 15%, Q 25%, H 30%) | |
container: { type: String, default: "svg" } | |
// container options: | |
// svg - populate squares in a SVG document with width and height attriute, recommended for converting to raster images or PDF where QR Code is being static (exact size) | |
// g - put squares in g element, useful when you need to put multiple QR Codes in a single SVG document | |
// none - no wrapper | |
}, | |
render(h) { | |
return h("div", { | |
domProps: { | |
innerHTML: new QRCodeSvg(this.$props).svg() | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
qrcode-compact-svg has a
save()
method you won't want since it dependsfs
module from NodeJS.Can apply styles to the outer
<div>
to resize, add padding, border etc.Example