gpt4 book ai didi

vue.js - '不提供名为 'createRouter' 的导出' vue 3、vite 和 vue-router

转载 作者:行者123 更新时间:2023-12-04 11:21:40 25 4
gpt4 key购买 nike

我刚开始在 vue 中使用 vite。
当我尝试使用 vue-router 时,出现错误:

SyntaxError: The requested module '/node_modules/.vite/vue-router/dist/vue-router.esm.js?v=4830dca4' does not provide an export named 'createRouter
我的路由器/index.js 看起来像这样:
import {
createWebHistory,
createRouter
} from "vue-router";

import Services from "../views/Services.vue";
import Costumers from "../views/Costumers.vue";

const history = createWebHistory();
const routes = [
{
path: "/",
component: Services
},
{
path: "/costumers",
component: Costumers
},
];
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"
}
}
有人知道如何导出路由吗?

最佳答案

您应该卸载当前的 vue-router 模块并通过运行以下命令重新安装与 Vue 3 兼容的最新(版本 4)模块:

npm uninstall vue-router
然后
npm install vue-router@next -S 

关于vue.js - '不提供名为 'createRouter' 的导出' vue 3、vite 和 vue-router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65858930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com