UNPKG

vue-files-preview-inno

Version:

A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.

55 lines (54 loc) 1.31 kB
import { defineComponent as m, ref as s, watch as i, openBlock as u, createElementBlock as f, createElementVNode as p } from "vue"; import { getFileRenderByFile as _, getFileRenderByUrl as h } from "../../utils/utils.mjs"; const g = { class: "pic-preview" }, v = ["src"], w = /* @__PURE__ */ m({ __name: "index", props: { file: { default: () => null }, url: { default: () => null }, name: {} }, emits: ["rendered", "error"], setup(l, { emit: a }) { const o = l, n = a, t = s(null); i( () => o.file, (r) => { r && _(r).then((e) => { t.value = e; }).catch((e) => { n("error", e); }); }, { immediate: !0 } ), i( () => o.url, (r) => { r && !o.file && h(r).then((e) => { t.value = e; }).catch((e) => { n("error", e); }); }, { immediate: !0 } ); function c() { n("rendered"); } function d() { n("error", new Error("Image load failed")); } return (r, e) => (u(), f("div", g, [ p("img", { src: t.value, alt: "", crossorigin: "anonymous", onLoad: c, onError: d }, null, 40, v) ])); } }); export { w as default }; //# sourceMappingURL=index.vue2.mjs.map