vuejs 3: Uncaught TypeError: Object(...) is not a function
vuejs 3: Uncaught TypeError: Object(...) is not a function
我无法摆脱这个错误。
有人提示这是为什么?
我在版本 3 中使用带有路由器的 vuejs。
Uncaught TypeError: Object(...) is not a function
npm run serve
WARNING Compiled with 2 warnings
warning in ./src/router.js "export 'createRouter' was not found in
'vue-router' warning in ./src/router.js "export 'createWebHistory'
was not found in '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 Router 4 与 Vue 3 一起使用
npm install vue-router@4
我无法摆脱这个错误。 有人提示这是为什么?
我在版本 3 中使用带有路由器的 vuejs。
Uncaught TypeError: Object(...) is not a function
npm run serve
WARNING Compiled with 2 warnings
warning in ./src/router.js "export 'createRouter' was not found in 'vue-router' warning in ./src/router.js "export 'createWebHistory' was not found in '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 Router 4 与 Vue 3 一起使用
npm install vue-router@4