Browse Source

解决二维码初始化只能拖拽一个的问题

zhoucg 1 năm trước cách đây
mục cha
commit
ec4a3d10cd
1 tập tin đã thay đổi với 9 bổ sung14 xóa
  1. 9 14
      src/components/yvan-ui/YvanPrintBarcode.vue

+ 9 - 14
src/components/yvan-ui/YvanPrintBarcode.vue

@@ -2,7 +2,8 @@
   <svg :id="barcodeId" :style="computeStyle"/>
 </template>
 
-<script>
+<script lang="js">
+import system from '@/utils/system'
 import JsBarcode from 'jsbarcode';
 
 export default {
@@ -27,16 +28,11 @@ export default {
   },
   data() {
     return {
-      barcodeId: 'barcode'
+      barcodeId: 'barcode-' + system.getUuid()
     }
   },
   mounted() {
     this.createBarcode(this.config)
-    this.$nextTick(() => {
-      const barcode = document.getElementById(this.barcodeId);
-      barcode.style.width = `${this.style.width}px`;
-      barcode.style.height = `${this.style.height}px`;
-    })
   },
   computed: {
     computeStyle() {
@@ -45,10 +41,13 @@ export default {
   },
   methods: {
     createBarcode(config) {
+      this.$nextTick(() => {
+        const barcode = document.getElementById(this.barcodeId);
+        barcode.style.width = `${this.style.width}px`;
+        barcode.style.height = `${this.style.height}px`;
+      })
       const barcode = document.getElementById(this.barcodeId);
-      JsBarcode(barcode, this.value, {
-        ...config,
-      });
+      JsBarcode(barcode, this.value, {...config});
     }
   },
   watch: {
@@ -61,7 +60,3 @@ export default {
   }
 }
 </script>
-
-<style scoped lang="less">
-
-</style>