gpt4 book ai didi

javascript - Vuejs - 未捕获的类型错误 : Cannot redefine property: $router

转载 作者:搜寻专家 更新时间:2023-10-30 22:19:03 24 4
gpt4 key购买 nike

我是 Vuejs 的新手,一段时间以来我一直被以下错误困扰:(在页面加载时出现)

Uncaught TypeError: Cannot redefine property: $router
  at Function.defineProperty ()
  at Function.install (VM2179 vue-router.esm.js:526)
  at Function.Vue.use (vue.js:4738)
  at eval (VM2179 vue-router.esm.js:2447)
  at Object../node_modules/vue-router/dist/vue-router.esm.js (VM2105 app.js:1615)
  at __webpack_require__ (VM2105 app.js:712)
  at fn (VM2105 app.js:95)
  at eval (VM2178 index.js:3)
  at Object../src/router/index.js (VM2105 app.js:2415)
  at __webpack_require__ (VM2105 app.js:712)

这个问题似乎并没有影响 web 应用程序的可用性,我很确定我没有多次声明 Vue.use(Router) ......

这是我的 index.js 文件:(在 src/router 中)

import Vue from 'vue'
import Router from 'vue-router'
import Blog from '../components/Blog.vue'
import BlogPost from '../components/BlogPost.vue'

Vue.use(Router)
Vue.config.silent = true

export default new Router({
routes: [
{
path: '/blog',
name: 'Blog',
component: Blog
},
{
path: '/blog/:slug',
name: 'Blog-post',
component: BlogPost
}
]
})

app.ts:(在 src 中,主入口点)

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/simple_store'
import '../assets/app.css'
import './assets/main_logo.css'
import './assets/pages/page_header_animation.css'

new Vue({
el: '#app',
router,
store,
render: h => h(App)
})

求助!谢谢!!

最佳答案

解决了!

在我的 index.html 文件中,我再次导入了 vue:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Meko Deng</title>
</head>
<body>
<div id="app"></div>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script> -->
</body>
</html>

注释掉就成功了!

关于javascript - Vuejs - 未捕获的类型错误 : Cannot redefine property: $router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52209717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com