how to import many vue component to my vue page?

Viewed 60

i dont want to write a lot of import from.

import button1 from './components/button1'
import button2 from './componnets/button2'
import table1 from './componnets/table2'
...

Is there any good way to do it quickly? How many way to do this thing?

3 Answers

following this pattern you can dynamically import components as well:

computed: {
  comp () {
      return () => import(`@/components/${this.componentName}.vue`)
  }
}

and then use it like:

<template>
    <component :is="comp"></component>
</template>
Related