vuejs2 - NUXT 中间件中的 Vue 路由器挂钩
问题描述
当我的用户更改路线时,我正在尝试关闭侧边栏
export default function({ store }) {
store.commit("TOGGLE_SIDEBAR");
}
问题是网站加载后立即调用它
我试试这个
export default function({ app, store }) {
app.router.beforeEach((to, next) => {
store.commit("TOGGLE_SIDEBAR");
next();
});
}
我明白了next is not a function.
我如何让这个工作?
解决方案
如文档 router.beforeEach(...)
中所述,需要一个具有 3 个参数的函数to
:from
和next
.
由于您只传递了两个参数,因此next
您尝试调用的参数实际上是from
Route。
添加第三个参数,如下所示:
export default function({ app, store }) {
app.router.beforeEach((to, from, next) => {
store.commit("TOGGLE_SIDEBAR");
next();
});
}
推荐阅读
- tomcat - 如何将流量从 Nginx 入口路由到应用程序 Tomcat 服务器
- jmeter - 使用 Jmeter 连接雪花 JDBC 连接器时收到错误
- r - 识别事件前后的行
- java - 如何在数据库连接中正确使用 try-with-resources?
- firebase - 谷歌云功能:无法加载默认凭据
- weblogic - com.oracle.weblogic.lifecycle.core.PartitionLCMService 错误
- php - Eloquent Query Builder 中的 Laravel 分页
- javascript - 编辑列表中的元素
- sql-server - SQL Server Service Broker 队列错误:“Service Broker 协议传输不可用”
- javascript - 一旦用户键入“#”,文本框中每个单词类型的下拉自动完成菜单