With Vue 3 Composition API, each view needs to have these:
import { useRouter, useRoute } from 'vue-router'
import { useStore } from 'vuex'
export default {
setup() {
const router = useRouter()
const store = useStore()
// ...
}
}
Is there a way to declare these somehow just once, pass them to the created app, and simply use them without these declarations inside the app views? With vue2, these were passed when app was initialized, then this.$store
/ this.$router
simply worked.
An idea with global vars, which can easily cause issues: in app.vue
, these could be declared once like this:
import { useStore } from 'vuex'
export default {
setup() {
globalthis.store = useStore()
then store
would work everywhere.