Uncaught TypeError: Cannot read properties of undefined (reading ‘use‘)
·
报错:Uncaught TypeError: Cannot read properties of undefined (reading ‘use’)
原因:Vue-router版本问题,在vue-router3可在router/index.js中安装router插件,但4不支持
解决:
1、在router/index.js中,导出{createRouter, createWebHistory}两个函数
使用createRouter来创建路由对象
使用createWebHistory函数赋值给history属性,因为是vue-router4所以必须有history属性,否则会报错
Uncaught Error: Provide the “history” option when calling “createRouter()”: https://next.router.vuejs.org/api/#history.
2、然后在main.js文件中安装路由插件
router/index.js
import {createRouter, createWebHistory} from 'vue-router'
const routes = [
{
path: '/hello',
component: () => import('../components/HelloWorld')
}
]
export default createRouter({
history: createWebHistory(),
routes
})
main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
const app = createApp(App)
app.use(router)
app.mount('#app')
更多推荐
已为社区贡献1条内容
所有评论(0)