Vuejs - 未捕获的类型错误:无法重新定义属性:$router [英] Vuejs - Uncaught TypeError: Cannot redefine property: $router

查看:82
本文介绍了Vuejs - 未捕获的类型错误:无法重新定义属性:$router的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Vuejs 比较陌生,并且我已经被以下错误困扰了一段时间:(页面加载时出现)

I'm relatively new to Vuejs and I’ve been stuck on with the following error for a while now: (Appears when page loads)

未捕获的类型错误:无法重新定义属性:$router
  在Function.defineProperty()
  at Function.install (VM2179 vue-router.esm.js:526)
  在 Function.Vue.use (vue.js:4738)
  在 eval (VM2179 vue-router.esm.js:2447)
  在 Object../node_modules/vue-router/dist/vue-router.esm.js (VM2105 app.js:1615)
  在 __webpack_require__ (VM2105 app.js:712)
  在 fn (VM2105 app.js:95)
  在 eval (VM2178 index.js:3)
  在 Object../src/router/index.js (VM2105 app.js:2415)
  在 __webpack_require__ (VM2105 app.js:712)

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) ......

This issue doesn't seem to be affecting the usability of the webapp and I’m pretty sure I’m not declaring Vue.use(Router) more than once…

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

Here is my index.js file: (in 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,主入口点)

app.ts: (in src, main entry point)

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)
})

请帮忙!谢谢!!

推荐答案

这是由于 以下代码vue-router

if (inBrowser && window.Vue) {
  window.Vue.use(VueRouter);
}

这实际上仅在您将文件包含在 <script> 块中时才存在(即,没有构建系统).

which is really only present for when you're including files in <script> blocks (ie, no build system).

删除任何与 Vue 或相关组件相关的

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆