Alex
Alex

Reputation: 375

How to lazy load vue2 component

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')
 }
)}

Upvotes: 1

Views: 1770

Answers (1)

huan feng
huan feng

Reputation: 8633

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> };

Upvotes: 1

Related Questions