Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue: lazy loading from library (Bootstrap-Vue) inside a component

I am exploring the lazy-loading feature and I'm trying to use it for Bootstrap-Vue component, but it does not work.

If I import the b-card "normally", it gets renderred correctly:

import { BCard } from 'bootstrap-vue';
export default {
    components: {
        BCard
    }
};

But when I'm attempting the 'lazy-load' syntax it does not work:

export default {
    components: {        
        BCard: () => import('bootstrap-vue').BCard
    }
};

The b-card component is not renderred, but no error is thrown and in Chrome's DOM inspection tools I can see that the placeholder <!----> is placed by Vue where the b-card component should be. I suspect that the library object that is loaded does not have the BCard property, but I don't know how else to access the library component with the 'lazy' syntax.

Is it possible to lazy-load a module from a library? How to do it?

like image 402
Eggon Avatar asked Nov 20 '25 10:11

Eggon


1 Answers

When dynamically importing a module, you use the import keyword as a function and it returns a promise. So, to access the module component, you can use this syntax:

export default {
  components: {
    BCard: () => import('bootstrap-vue').then(module => module.BCard)
  }
}
like image 91
steve16351 Avatar answered Nov 21 '25 23:11

steve16351



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!