我正在使用一个名为夹持带的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;当我的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 { }router.d.ts文件如下所示

发布于 2021-10-26 16:10:45
我认为你在使用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发布于 2021-09-01 13:34:30
从技术上讲,你没有问问题,我会尽力解释错误的。您的错误说明您试图做什么,从不存在的模块'vue‘导入默认导出。
// some ts file
import Vue from "vue";
// the module
export default {}如果应该有一个名为“Vue”的名导出,您应该按以下方式编写它:import { Vue } from 'vue'
参考资料:
https://stackoverflow.com/questions/69013483
复制相似问题