UNPKG

@chenfengyuan/vue-barcode

Version:
62 lines (59 loc) 1.45 kB
/*! vue-barcode v2.0.2 | (c) 2018-present Chen Fengyuan | MIT */ import { defineComponent, h } from 'vue'; import JsBarcode from 'jsbarcode'; var index = defineComponent({ name: 'VueBarcode', props: { /** * The value of the bar code. */ value: { type: String, default: undefined, }, /** * The options for the bar code generator. * {@link https://github.com/lindell/JsBarcode#options} */ options: { type: Object, default: undefined, }, /** * The tag name of the component's root element. */ tag: { type: String, default: 'canvas', }, }, watch: { $props: { deep: true, immediate: true, /** * Update the bar code when props changed. */ handler() { if (this.$el) { this.generate(); } }, }, }, mounted() { this.generate(); }, methods: { /** * Generate bar code. */ generate() { JsBarcode(this.$el, String(this.value), this.options); }, }, render() { return h(this.tag, this.$slots.default); }, }); export { index as default };