【问题标题】:Cannot read property of listen of undefined Vue-Router-next无法读取未定义的 Vue-Router-next 的监听属性
【发布时间】:2020-09-09 10:40:45
【问题描述】:

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

得到错误

未捕获的类型错误:无法读取未定义的属性“侦听” 在 createRouter (vue-router.esm-bundler.js:2269) 在 main.js:16 createRouter@vue-router.esm-bundler.js:2269 (匿名)@main.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')

【问题讨论】:

    标签: vue-router vuejs3


    【解决方案1】:

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

    import { createRouter, createWebHistory } from 'vue-router'
    // there is also createWebHashHistory and createMemoryHistory
    
    createRouter({
      history: createWebHistory(),
      routes: [],
    })
    

    【讨论】:

    • 我得到 createWebHistory 不是一个函数,当我打印它时它是未定义的。可能是什么问题
    • 对不起@Abhi,但您应该包含一个代码框,我无法使用以下代码框复制codesandbox.io/s/vue-router-v4-reproduction-l5fzm?file=/…
    • Nvm。这是因为 createWebHistory 可从 Vue 路由器 v4 获得,而我使用的是 3.3.7
    猜你喜欢
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 2019-01-30
    • 2019-11-22
    • 2021-12-08
    • 2021-03-29
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多