this.$router.push报错
时间: 2023-09-11 14:07:38 浏览: 101
解决vue.js this.$router.push无效的问题
5星 · 资源好评率100%
this.$router.push报错是因为最新版的vue-router引入了promise,当使用this.$router.push()时会返回一个promise对象。如果没有捕获这个promise对象,就会出现Uncaught (in promise)错误。解决这个问题的方法有两种。第一种方法是直接在push()后调用一个catch方法,例如this.$router.push(this.path).catch(err=>err)。第二种方法是重写原型中的push方法,具体的代码可以参考这个链接:https://blog.csdn.net/haidong55/article/details/100939076。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [$route.push()多次点击跳转报错问题](https://blog.csdn.net/qq_52693197/article/details/124692850)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [调用$router.push()时报出Uncaught (in promise)错误](https://blog.csdn.net/weixin_42761614/article/details/113346398)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文