Explorar o código

解决二维码初始化大小问题

zhoucg hai 1 ano
pai
achega
504a660a8a
Modificáronse 1 ficheiros con 5 adicións e 5 borrados
  1. 5 5
      src/components/yvan-ui/YvanPrintBarcode.vue

+ 5 - 5
src/components/yvan-ui/YvanPrintBarcode.vue

@@ -1,5 +1,5 @@
 <template>
-  <svg id="barcode" :style="computeStyle"/>
+  <svg :id="barcodeId" :style="computeStyle"/>
 </template>
 
 <script>
@@ -27,14 +27,13 @@ export default {
   },
   data() {
     return {
-      barcodeWidth: this.style.width + 'px',
-      barcodeHeight: this.style.height + 'px',
+      barcodeId: 'barcode'
     }
   },
   mounted() {
     this.createBarcode(this.config)
     this.$nextTick(() => {
-      const barcode = document.getElementById('barcode');
+      const barcode = document.getElementById(this.barcodeId);
       barcode.style.width = `${this.style.width}px`;
       barcode.style.height = `${this.style.height}px`;
     })
@@ -46,7 +45,8 @@ export default {
   },
   methods: {
     createBarcode(config) {
-      JsBarcode("#barcode", this.value, {
+      const barcode = document.getElementById(this.barcodeId);
+      JsBarcode(barcode, this.value, {
         ...config,
       });
     }