lazy load vue components from another server #6495
Unanswered
lampewebdev
asked this question in
Q&A
Replies: 1 comment 3 replies
-
I struggle with the same problem, we want to load external created components into our application at runtime. Edit: so i have build a vite lib and created a simple webserver in express serving this file my-lib.umd.js (function(e,t){typeof exports=="object"&&typeof module<"u"?module.exports=t(require("vue")):typeof define=="function"&&define.amd?define(["vue"],t):(e=typeof globalThis<"u"?globalThis:e||self,e.MyLib=t(e.Vue))})(this,function(e){"use strict";const t=(n,o)=>{const c=n.__vccOpts||n;for(const[d,f]of o)c[d]=f;return c},i={},s=[e.createElementVNode("h1",null,"Test!",-1)];function r(n,o){return e.openBlock(),e.createElementBlock("div",null,s)}return t(i,[["render",r]])}); the i created a fresh vue 3 application and tried loading that library. <template>
<div>
<component :is="dynamicComponent"></component>
</div>
</template>
<script>
export default {
data() {
return {
dynamicComponent: null,
};
},
async created() {
const module = await import(`http://localhost:8200/Test/my-lib.umd.js`);
this.dynamicComponent = module;
},
};
</script>
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have a big app, and we want to load some parts of the app after the page has rendered.
We would like to use 'defineAsyncComponent' but the problem is that the component is on another server.
So what we basically want is:
This is right now not working with vite and vite-ssr-plugin.
Any Idea how to we can do this?
Beta Was this translation helpful? Give feedback.
All reactions