javascript – Vuejs – 未捕获的TypeError:无法重新定义属性:$router
作者:互联网
我对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)
这个问题似乎没有影响webapp的可用性,我很确定我不会多次声明Vue.use(路由器)……
这是我的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)
})
请帮忙!
谢谢!!
解决方法:
这是由于vue-router中的following code
if (inBrowser && window.Vue) {
window.Vue.use(VueRouter);
}
这实际上仅适用于在< script>中包含文件的情况块(即没有构建系统).
删除所有< script>与Vue或相关组件有关的要素;使用Webpack时不需要它们.
标签:vue-router,javascript,vue-js,vuejs2 来源: https://codeday.me/bug/20190823/1697259.html