UNPKG

@chenfengyuan/vue-qrcode

Version:
2 lines 1.11 kB
/*! vue-qrcode v2.0.0 | (c) 2018-present Chen Fengyuan | MIT */ import{defineComponent as e,h as t}from"vue";import{toString as s,toDataURL as i,toCanvas as r}from"qrcode";var a=e({name:"VueQrcode",props:{value:{type:String,default:void 0},options:{type:Object,default:void 0},tag:{type:String,default:"canvas"}},emits:["ready"],watch:{$props:{deep:!0,immediate:!0,handler(){this.$el&&this.generate()}}},mounted(){this.generate()},methods:{generate(){const e=this.options||{},t=String(this.value),a=()=>{this.$emit("ready",this.$el)};switch(this.tag){case"canvas":r(this.$el,t,e,(e=>{if(e)throw e;a()}));break;case"img":i(t,e,((e,t)=>{if(e)throw e;this.$el.src=t,this.$el.onload=a}));break;case"svg":s(t,e,((e,t)=>{if(e)throw e;const s=document.createElement("div");s.innerHTML=t;const i=s.querySelector("svg");if(i){const{attributes:e,childNodes:t}=i;Object.keys(e).forEach((t=>{const s=e[Number(t)];this.$el.setAttribute(s.name,s.value)})),Object.keys(t).forEach((e=>{const s=t[Number(e)];this.$el.appendChild(s.cloneNode(!0))})),a()}}))}}},render(){return t(this.tag,this.$slots.default)}});export{a as default};