我正在使用一个名为gritape(用于区块链)的js框架。我在尝试使用 vue 路由器时遇到此错误。
import Vue from "vue"; //Error **does not provide an export named 'default'**
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "Home",
component: Home,
},
{
path: "/about",
name: "About",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "../views/About.vue"),
},
];
const router = new VueRouter({
routes,
});
export default router;
Run Code Online (Sandbox Code Playgroud)
虽然我的vue.d.ts文件看起来像这样
import { CompilerOptions } from '@vue/compiler-dom';
import { RenderFunction } from '@vue/runtime-dom';
export declare function compile(template: string | HTMLElement, options?: CompilerOptions): RenderFunction;
export * from "@vue/runtime-dom";
export { }
Run Code Online (Sandbox Code Playgroud)
我认为你正在使用Vue 3. 你应该检查你的vue-router版本。如果你npm i vue-router现在才运行,版本应该是“^3.5.3”。尝试使用npm i vue-router@next安装较新版本。
然后像这样导出路由器:
import {createRouter, createWebHistory} from 'vue-router'
const routes = [
{
path:'/',
name:"Home",
component:()=>import('./pages/Home.vue')
}
,
{
path:'/about',
name:"About",
component:()=>import('./pages/About.vue')
}
]
const router = createRouter({
history:createWebHistory(),
routes
})
export default router
Run Code Online (Sandbox Code Playgroud)