我正在嘗試創(chuàng)建一個 Vue SPA 應(yīng)用程序。但是該路由似乎與我在路由器中定義的不匹配。我不明白為什么會這樣。據(jù)我所知,一切都應(yīng)該正常工作。我在這里缺少什么?我的 index.html<html> <head> <title>New Vue.js Project</title> <script src="assets/js/vue.js"></script> <script src="assets/js/vue-router.js"></script> </head> <body> <div id="app"> {{ 'Route: ' + JSON.stringify($route) }} <v-app> <router-view></router-view> </v-app> </div> <script type="module" src="app.js"></script> </body></html>我的 app.jsimport routes from './routes.js'new Vue({ el: '#app', router: routes, data: { msg: 'Hello World!', },})我的路線.jsimport Index from './views/Index.js'Vue.use(VueRouter)export default new VueRouter({ mode: 'history', routes: [ { name: 'index', path: '/', component: Index, }, ],})當(dāng)我導(dǎo)航到http://localhost/new-vue-project/并打印 {{ $route }} 我得到這個:{ "name":null, "path":"/new-vue-project/", "fullPath":"/new-vue-project/", "matched": [ ]}我還嘗試向路由器添加基本屬性,但得到了相同的結(jié)果。base: 'http://localhost/new-vue-project/',
即使定義了 Vue.js 路由也不匹配
BIG陽
2021-09-17 17:10:38