Home > Net >  How to lazy load vue2 component
How to lazy load vue2 component

Time:10-27

Is it possible to do that?

Tried

 components: {
  Fibonacci: () => import('./Fibonacci.vue')
 }

But Eslint warning about import (Parsing error: Unexpected token import). What need to change?

upd:

new Vue({
 components: { 
  Fibonacci: () => import('./Fibonacci.vue')
 }
)}

CodePudding user response:

You can refer to this plugin: https://github.com/xunleif2e/vue-lazy-component

If you mean a page component, I think you should use vue-router if you want to lazy load a component.

BTW, i don't see components option accept a function.

components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> };
  • Related