我刚开始在vue中使用vite.

当我试图使用vue路由时,我得到一个错误:

SyntaxError:请求的模块'/node_modules/.vite/vue路由/dist/vue路由.esm.js?v=4830dca4'不提供名为'createRouter'的导出

我的路由/索引.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;

我的主菜.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路由模块,并通过运行以下命令重新安装与vue 3兼容的最新(版本4):

npm uninstall vue-router

然后

npm install vue-router@next -S 

Vue.js相关问答推荐

Nuxt3: 安装vue3-spinner (error: require is not defined in ES module scope)

vue js如何将布尔值传到数据库

绑定事件在渲染函数中不起作用

何时将代码拆分为 Nuxt 中的组件?

如何对对象数组进行 v-model

使用 jquery-chosen 插件更新 vuejs 模型值

如何渲染数组以 Select 选项 vue.js

如何将参数传递给使用 ...mapActions(...) 映射的函数?

Vue 3 - 带有全局组件的无法解析组件

在 vue/vuex(/flux?) 中使用 ES6 类是一种反模式吗?

当 v-for 与对象的属性一起使用时,将 v-model 与复选框一起使用

使用 Spring Boot(VueJS 和 Axios 前端)禁止发布 403 帖子

Vue Chart.js - 条形图上的简单点/线

emit更新数组不起作用

依赖关系甚至在 package.json 和 node_modules 中都没有定义

如何设置 :id 前缀字符串?

如何在 Promise 回调中更新 Vue 应用程序或组件的属性?

在~/components/AddPlaceModal.vue中找不到导出AddPlaceModal

在 Vue 中使用事件修饰符 .prevent 提交表单而不进行重定向

使用 vue.js 获取调用元素