@chenfengyuan/vue-barcode
Version:
Bar code component for Vue 3.
71 lines (65 loc) • 2.14 kB
JavaScript
/*! vue-barcode v2.0.2 | (c) 2018-present Chen Fengyuan | MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue'), require('jsbarcode')) :
typeof define === 'function' && define.amd ? define(['vue', 'jsbarcode'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VueBarcode = factory(global.Vue, global.JsBarcode));
})(this, (function (vue, JsBarcode) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var JsBarcode__default = /*#__PURE__*/_interopDefaultLegacy(JsBarcode);
var index = vue.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__default["default"](this.$el, String(this.value), this.options);
},
},
render() {
return vue.h(this.tag, this.$slots.default);
},
});
return index;
}));