yuang-framework-ui-pc
Version:
yuang-framework-ui-pc Library
68 lines (67 loc) • 1.6 kB
JavaScript
import { defineComponent, ref, watch, nextTick, onMounted, createBlock, openBlock, resolveDynamicComponent, normalizeStyle } from "vue";
import JsBarCode from "jsbarcode";
import { barCodeProps } from "./props";
const _sfc_main = defineComponent({
name: "EleBarCode",
props: barCodeProps,
setup(props) {
const rootRef = ref(null);
const instance = ref(null);
const render = () => {
if (!props.value || !rootRef.value) {
return;
}
try {
instance.value = new JsBarCode(
rootRef.value,
props.value,
props.options
);
} catch (e) {
console.error(e);
}
};
watch(
() => props.value,
() => {
render();
}
);
watch(
() => props.options,
() => {
render();
},
{ deep: true }
);
watch(
() => props.tag,
() => {
nextTick(() => {
render();
});
}
);
onMounted(() => {
render();
});
return { rootRef, instance, render };
}
});
const _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), {
ref: "rootRef",
style: normalizeStyle(_ctx.value ? void 0 : { display: "none" })
}, null, 8, ["style"]);
}
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
index as default
};