vuejs 3:未捕获的类型错误:对象(...)不是函数[重复]
Posted
技术标签:
【中文标题】vuejs 3:未捕获的类型错误:对象(...)不是函数[重复]【英文标题】:vuejs 3: Uncaught TypeError: Object(...) is not a function [duplicate] 【发布时间】: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')
【问题讨论】:
【参考方案1】:您需要将 Vue Router 4 与 Vue 3 一起使用
npm install vue-router@4
【讨论】:
以上是关于vuejs 3:未捕获的类型错误:对象(...)不是函数[重复]的主要内容,如果未能解决你的问题,请参考以下文章
VueJs 3 - Vuex:未捕获的类型错误:存储不是函数
VueJS 3 + Laravel:未捕获的类型错误:无法读取未定义的属性“组件”
VueJS 3 / 路由器 / 带有推送的重定向:未捕获(承诺中)类型错误:无法读取未定义的属性(读取“推送”)
Vuejs - 未捕获的类型错误:无法重新定义属性:$router