Here are the files I am working with:
router.js
import VueRouter from 'vue-router'
export const router = VueRouter({
routes: [
{
...
}
]
})
main.js
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
...
import { router } from './router'
app.use(router)
...
app.mount('#app')
After setting up my project this way, I encountered the error message Uncaught
TypeError: this is undefined - vue-router.esm.js:2828
, which seems to originate from line 2828 within the vue-router library.
This issue arises even when simply importing vue-router without utilizing it elsewhere in the application. Strangely, I have successfully imported vuex using a similar import/export approach without any problems.
I suspect that my method of importing vue-router may be incorrect since the official documentation does not include the use of {createApp}
. Is there an error in my import process, or could there be another underlying reason for this malfunction?