Skip to content

Instantly share code, notes, and snippets.

@SynCap
Created March 3, 2020 15:22
Show Gist options
  • Save SynCap/87512a76d213cd3a743d5b9ac5c28206 to your computer and use it in GitHub Desktop.
Save SynCap/87512a76d213cd3a743d5b9ac5c28206 to your computer and use it in GitHub Desktop.
Nuxt components automatic registration

in nuxt.config:

....

  /*
   ** Plugins to load before mounting the App
   */
  plugins: ['~/plugins/autoloads.js' /*, ... */],

....
import Vue from 'vue'
// Variant #1
[ 'FDummy' ].forEach(name => Vue.component(name, () => import(`~/components/${name}.vue`)))
import Vue from 'vue'
// Variant #2
const components = { FDummy /*, .... */ }
import FDummy from '@/components/FDummy.vue'
/*
....
....
*/
Object.entries(components).forEach(([name, component]) => {
Vue.component(name, component)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment