[Vue warn]: injection “Symbol(router)” not found.

当前问题

vue3,使用路由的时候报错main.ts:8 [Vue warn]: injection “Symbol(router)” not found.
at <RouterLink to= {path: ‘/home’} active-class=“active” >
at

解决方案

原来是在main.ts代码的顺序

import { createApp } from "vue";
import App from "./App.vue";
import router from "./Day04/router";

// 创建app对象
const app = createApp(App);
// 创建挂载
app.mount("#app");
// 引用路由
app.use(router);

正确的应该是

import { createApp } from "vue";
import App from "./App.vue";
import router from "./Day04/router";

// 创建app对象
const app = createApp(App);
// 引用路由
app.use(router);
// 创建挂载
app.mount("#app");

应该是先引入路由之后再挂载

Logo

前往低代码交流专区

更多推荐