我刚开始在 vue 中使用 vite。
当我尝试使用 vue-router 时,出现错误:
SyntaxError:请求的模块“/node_modules/.vite/vue-router/dist/vue-router.esm.js?v=4830dca4”不提供名为“createRouter”的导出
我的 router/index.js 看起来像这样:
import {
createWebHistory,
createRouter
} from "vue-router";
import Services from "../views/Services.vue";
import Customers from "../views/Customers.vue";
const history = createWebHistory();
const routes = [
{
path: "/",
component: Services
},
{
path: "/customers",
component: Customers
},
];
const router = createRouter({
history,
routes
});
export default router;
我的 main.js 看起来像这样:
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
import router from './router'
createApp(App).use(router).mount('#app')
我的 package.json 看起来像这样:
{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"vue": "^3.0.5",
"vue-router": "^3.4.9"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.0.4",
"@vue/compiler-sfc": "^3.0.5",
"autoprefixer": "^10.2.3",
"postcss": "^8.2.4",
"tailwindcss": "^2.0.2",
"vite": "^2.0.0-beta.12"
}
}
有人知道如何导出路线吗?