DEV Community

Discussion on: Registering Global Components with Vue 3

Collapse
 
jackzhoumine profile image
jackzhoumine

Can i do this way?
in index.js

import WatchTest from './WatchTest.vue'
const components = [WatchTest]
export default {
    install(Vue) {
        components.forEach((component) => {
            Vue.use(component.name, component)
        })
    },
}
Enter fullscreen mode Exit fullscreen mode

in main.js

import components from './components'
const vue = createApp(App)
vue.use(components)
Enter fullscreen mode Exit fullscreen mode

it does not work? how to register global component using install?