0

https://codesandbox.io/s/vue-router-v4-reproduction-l5fzm?file=/index.html

得到错误

未捕获的类型错误:无法在 main.js:16 createRouter @ vue-router.esm-bundler.js:2269(匿名)@ main 处的 createRouter (vue-router.esm-bundler.js:2269) 处读取未定义的属性“listen” .js:16

代码示例:如何重现

const { createRouter, createWebHistory, createWebHashHistory } = VueRouter
const { createApp } = Vue

const Home = {
  template: `<div>home</div>`,
}

const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }

const router = createRouter({
  routes: [
    { path: '/', component: Home },
    { path: '/foo', component: Foo },
    { path: '/bar', component: Bar },
  ],
})

const app = createApp({})
app.use(router)

window.vm = app.mount('#app')
4

1 回答 1

2

似乎历史键是必需的参数,并在vue-router-next文档中解决。

import { createRouter, createWebHistory } from 'vue-router'
// there is also createWebHashHistory and createMemoryHistory

createRouter({
  history: createWebHistory(),
  routes: [],
})
于 2020-05-22T14:43:44.783 回答