cretueusebiu / laravel-nuxt

A Laravel-Nuxt starter kit.
https://laravel-nuxt.cretueusebiu.com
MIT License
1.15k stars 262 forks source link

Global Component not working. #154

Closed huonsokly closed 2 years ago

huonsokly commented 2 years ago

I've tried to declare global component but it not working however I did like this in single nuxt project it worked fine.

//plugins/ml.js import Vue from 'vue' import Title from '~/components/ml/title'; const components = { Title }; Object.entries(components).forEach(([name, component]) => { Vue.component(name, component) });

//nuxt.config.js plugins: [ '~plugins/ml', ]

//in view file <ml-title></ml-title>

but not working, please help!

cretueusebiu commented 2 years ago

Just use Vue.component(Title.name, Title)

huonsokly commented 2 years ago

Thank you for your answer! but will it work with multiple components?

//plugins/ml.js import Vue from 'vue' import Title from '~/components/ml/title'; import Title2 from '~/components/ml/title2'; const components = { Title, Title2 }; Object.entries(components).forEach(([name, component]) => { Vue.component(name, component) });

Thank you

huonsokly commented 2 years ago

I added this

components: { dirs: [ '~/components/', { path: '~/components/ml/', prefix: 'ml' } ] },

in nuxt.config.js and it worked. thank you!