javascript - 无法重新定义属性:$router,可能重复 Vue.use(VueRouter)
问题描述
我的 Vue 应用程序中有几条路线。但是,刷新页面只会在特定的 2 条路线中导致永无止境的循环。我从 chrome 控制台收到的错误是
VM10283:55826 Uncaught TypeError: Cannot redefine property: $router
at Function.defineProperty (<anonymous>)
at Function.install (<anonymous>:55826:10)
at Function.Vue.use (app.js:62595)
at Module../node_modules/vue-router/dist/vue-router.esm.js (<anonymous>:57490:14)
at __webpack_require__ (<anonymous>:20:30)
at Module../resources/js/app.js (<anonymous>:71691:68)
at __webpack_require__ (<anonymous>:20:30)
at Object.0 (<anonymous>:74685:1)
at __webpack_require__ (<anonymous>:20:30)
at <anonymous>:84:18
以下是我的代码
应用程序.js
import VueRouter from 'vue-router'
import routes from '@/js/router'
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
hash: false,
routes
});
const app = new Vue({
el: '#app',
store,
router,
components: { App },
template: '<App/>',
});
路由器/index.js
import Home from '@/js/components/Home.vue';
import store from '@/js/store'
export default [
{
path: '/',
name: 'home',
beforeEnter: publicAuth,
component: Home,
meta: {
title: 'Home',
}
},
{
path: '/user/profile',
name: 'user.profile',
beforeEnter: auth,
component: Profile,
meta: {
title: 'Profile',
}
},
...
在 SO 上搜索后,我意识到这可能是由 引起的Vue.use(VueRouter)
,我已经尝试了网络上的所有方法,但没有找到解决方案。
谢谢
解决方案
推荐阅读
- reactjs - 使用 Shopify Collection 在 Gatsby 中以编程方式创建页面
- python - 使用 Kmeans 的错误结果自动编码器(IRV2 功能)
- html - CSS 特异性基于与元素的接近度而不是 CSS 代码中的顺序
- javascript - app.js 在反应中为自定义钩子抛出未定义但为另一个工作
- c# - 激活事件时将数据从 userControl 传递到表单
- postgresql - 在 Oracle 的查询中使用 oracle_fdw 比较操作时 PostgreSQL 太慢
- sql-server - 创建 SSRS 报告,显示每个 RDL 和订阅(如果有多个)的订阅失败历史计数
- encryption - 在 Unqork 中对字符串进行哈希加密
- laravel - 如何将多个域链接到一个 Laravel 项目?
- zsh - zsh 的 tab 补全会覆盖接下来的内容