ElemBarcode.vue 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <div class="elem-barcode" :style="styles">
  3. <img v-if="imageSrc" :src="imageSrc" alt="条形码" />
  4. <img
  5. v-else
  6. src="../../assets/images/barcode-sample-notext.png"
  7. alt="条形码"
  8. />
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. name: "elem-barcode",
  14. props: {
  15. data: {
  16. type: Object
  17. }
  18. },
  19. computed: {
  20. styles() {
  21. return {
  22. backgroundColor: this.data.bgColor,
  23. borderStyle: this.data.style,
  24. borderWidth: this.data.bold,
  25. borderColor: this.data.color,
  26. transform: `rotate(${this.data.rotation}deg)`
  27. };
  28. },
  29. imageSrc() {
  30. // 设置变量之后的条形码,在渲染时将content的内容填充为base64字符图片。
  31. const content = this.data.content;
  32. return content && content.indexOf("base64") !== -1 ? content : "";
  33. }
  34. },
  35. data() {
  36. return {};
  37. },
  38. methods: {}
  39. };
  40. </script>