【问题标题】:vuejs 3: Uncaught TypeError: Object(...) is not a function [duplicate]vuejs 3:未捕获的类型错误:对象(...)不是函数[重复]
【发布时间】:2021-06-29 14:29:00
【问题描述】:

我无法摆脱错误。 有人提示为什么会这样?

我在版本 3 中使用带有路由器的 vuejs。

Uncaught TypeError: Object(...) is not a function

npm run serve

警告编译时有 2 个警告
./src/router.js 中的警告“未找到导出‘createRouter’ ./src/router.js 中的“vue-router”警告“导出‘createWebHistory’ 在“vue-router”中找不到

router.js:

import { createWebHistory, createRouter } from "vue-router";
import UserSettings from "@/views/UserSettings.vue";
import UserEmailsSubscriptions from "@/views/UserEmailsSubscriptions.vue";
import UserProfile from "@/views/UserProfile.vue";
import UserProfilePreview from "@/views/UserProfilePreview.vue";
import Home from "@/views/Home.vue";
import About from "@/views/About.vue";
import Notfound from "@/views/Notfound.vue";

const routes = [
  { path: "/:catchAll(.*)", name: "Notfound", component: Notfound },
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/about",
    name: "About",
    component: About,
  },
  {
    path: "/settings",
    // You could also have named views at tho top
    component: UserSettings,
    children: [
      {
        path: "emails",
        component: UserEmailsSubscriptions,
      },
      {
        path: "profile",
        components: {
          default: UserProfile,
          helper: UserProfilePreview,
        },
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;

App.vue

<template>
  <h1>Nested Named Views</h1>
  <router-view />
</template>

<script lang="ts">
export default {
  name: 'App'
};
</script>

main.js

"use strict";
exports.__esModule = true;

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

createApp(App).use(router).mount('#app')

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    您需要将 Vue Router 4 与 Vue 3 一起使用

    npm install vue-router@4
    

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2014-06-20
      • 2015-08-18
      • 1970-01-01
      • 2015-11-20
      • 2020-10-28
      • 2016-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多