emis-frontend/src/components/Barcode/index.vue
2024-06-22 01:55:32 +08:00

45 lines
739 B
Vue

<script>
import { defineComponent, h } from 'vue';
import JsBarcode from 'jsbarcode'
export default defineComponent({
name: "VueBarcode",
props: {
value: {
type: String,
default: undefined,
},
options: {
type: Object,
default: undefined,
},
tag: {
type: String,
default: 'canvas',
},
},
watch: {
$props: {
deep: true,
immediate: true,
handler() {
if (this.$el) {
this.generate();
}
},
}
},
mounted(){
this.generate();
},
methods: {
generate() {
JsBarcode(this.$el, String(this.value), this.options);
},
},
render() {
return h(this.tag, this.$slots.default);
},
});
</script>