新VueJs项目中的路由组件无效

jogvjijk  于 2023-10-23  发布在  Vue.js
关注(0)|答案(1)|浏览(117)

我正在处理一个Vue.js项目,遇到了一个错误,说“错误:无效的路由组件。”我无法找出此问题的根本原因。有人能帮我诊断和解决吗?

import { createRouter, createWebHistory } from "vue-router";
import Home from '../views/Home.vue' 
const routes = [
  {
    path: "/",
    name: "home",
    component: "Home",
  },
];
const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;
<template> 
  <router-view />
</template>

<script setup> 

</script>

<style scoped> 
</style>
import { createApp } from "vue";
import router from "./router";
import "./style.css";
import App from "./App.vue";

createApp(App)
    .use(router)
    .mount("#app");
<template>
    Home
</template>

<script setup>
</script>
qcbq4gxm

qcbq4gxm1#

看看component的值,它是一个字符串,它应该是对Home导入的引用:

import Home from '../views/Home.vue' 
const routes = [
  {
    path: "/",
    name: "home",
    component: Home, // <---- use Home, not "Home"
  },
];

给予一次机会。

相关问题