UNPKG

@chenfengyuan/vue-qrcode

Version:
2 lines 1.34 kB
/*! vue-qrcode v2.0.0 | (c) 2018-present Chen Fengyuan | MIT */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue"),require("qrcode")):"function"==typeof define&&define.amd?define(["vue","qrcode"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueQrcode=t(e.Vue,e.QRCode)}(this,(function(e,t){"use strict";const i="ready";return e.defineComponent({name:"VueQrcode",props:{value:{type:String,default:void 0},options:{type:Object,default:void 0},tag:{type:String,default:"canvas"}},emits:[i],watch:{$props:{deep:!0,immediate:!0,handler(){this.$el&&this.generate()}}},mounted(){this.generate()},methods:{generate(){const e=this.options||{},o=String(this.value),s=()=>{this.$emit(i,this.$el)};switch(this.tag){case"canvas":t.toCanvas(this.$el,o,e,(e=>{if(e)throw e;s()}));break;case"img":t.toDataURL(o,e,((e,t)=>{if(e)throw e;this.$el.src=t,this.$el.onload=s}));break;case"svg":t.toString(o,e,((e,t)=>{if(e)throw e;const i=document.createElement("div");i.innerHTML=t;const o=i.querySelector("svg");if(o){const{attributes:e,childNodes:t}=o;Object.keys(e).forEach((t=>{const i=e[Number(t)];this.$el.setAttribute(i.name,i.value)})),Object.keys(t).forEach((e=>{const i=t[Number(e)];this.$el.appendChild(i.cloneNode(!0))})),s()}}))}}},render(){return e.h(this.tag,this.$slots.default)}})}));