不打开开发工具,路由可以正常跳转,打开开发工具后就报错且无法正常进行路由的跳转
/router/index.js
import {
createRouter,
createWebHashHistory
} from "vue-router"
const routes = [
{
path: "/",
redirect: "/test1"
},
{
path: '/test1',
name: "test1",
component: () => import('@/pages/test1')
},
{
path: '/test2',
name: "test2",
component: () => import('@/pages/test2')
},
]
export const router = createRouter({
history: createWebHashHistory('/'),
routes: routes
})
test1.vue
<template>
<h1>我是test1</h1>
<button @click="toTest2">toTest2</button>
</template>
<script>
import { useRoute, useRouter } from 'vue-router'
export default {
name: 'Test1',
setup () {
const route = useRoute()
const router = useRouter()
const toTest2= (async() => {
router.push("/test2")
})
return {
toTest2
}
},
}
</script>
test2.vue
<template>
<h1>我是test2</h1>
<button @click="toTest1">toTest1</button>
</template>
<script>
import { useRoute, useRouter } from 'vue-router'
export default {
name: 'Test2',
setup () {
const route = useRoute()
const router = useRouter()
const toTest1 = (async() => {
router.push("/test1")
})
return {
toTest1
}
},
}
</script>
错误信息
Uncaught (in promise) TypeError: api.now is not a function
at eval (vue-router.esm-bundler.js?ec2d:2489:1)
at eval (vue-router.esm-bundler.js?ec2d:3296:1)
at Array.forEach ()
at triggerError (vue-router.esm-bundler.js?ec2d:3296:1)
at eval (vue-router.esm-bundler.js?ec2d:3037:1)