出现这个问题,那么很有可能还是按照vue2的方式使用的Vue Router,建议先去了解下Vue Router 3。
解决问题示例代码如下:
//router.js import * as vueRouter from "vue-router"; import Home from "../views/Home.vue"; const routes = [ { path: "/index", name: "Home", component: Home } ]; const router = vueRouter.createRouter({ history: vueRouter.createWebHistory(), routes: routes }); export default router;
或者:
//router.js import {createRouter,createWebHistory} from "vue-router"; import Home from "../views/Home.vue"; const routes = [ { path: "/index", name: "Home", component: Home } ]; const router = createRouter({ history: createWebHistory(), routes: routes }); export default router;
//main.js import { createApp } from 'vue' import App from './App.vue' import router from './router' createApp(App).use(router).mount('#app')
如上,vue3跟vue2的区别还是蛮大的,所以使用之前建议还是先去了解下vue3与vue2的区别。