P粉6800005552023-08-25 13:31:15
In Vue 3, you can use the application API mixin method.
import { createApp } from 'vue' import App from './App.vue' import globalMixin from './globalMixin' const app = createApp(App) app.mixin(globalMixin) app.mount('#app')
For components, you can add them one by one. I prefer this way because it's clearer.
P粉7764125972023-08-25 13:14:46
In Vue 3, local component registration and mixins are possible in the root component (very useful when trying to avoid polluting the global namespace). Use extends
options to extend the component definition of App.vue
, then add your own mixins
and components
options :
import { createApp } from 'vue' import App from './App.vue' import Hello from './components/Hello.vue' import Thing from './components/Thing.vue' import globalMixin from './globalMixin' createApp({ extends: App, mixins: [globalMixin], components: { Hello, Thing, } }).mount('#app')
Registering components one by one seems like a good approach, especially if there are only a few components.