UNPKG

vue-hooks-plus

Version:
32 lines (31 loc) 814 B
"use strict"; const marked = require("marked"); const vue = require("vue"); function usePreview(md) { const container = vue.ref(); const mdCompute = vue.computed(() => vue.unref(md)); vue.watchEffect((onInvalidate) => { if (mdCompute.value && container.value) { try { if (typeof mdCompute.value === "string") { const html = marked.marked.parse(mdCompute.value); if (html) container.value.innerHTML = html; } else { const app = vue.createApp(mdCompute.value); app.mount(container.value); } } catch (error) { console.log(error); } } onInvalidate(() => { if (container.value) container.value.innerHTML = ""; }); }); return { container }; } module.exports = usePreview;