vue.js - this.$router.go() vs this.$router.push()
本文介绍了vue.js - this.$router.go() vs this.$router.push()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
vue.js里面想通过点击按钮=》发送post请求=》根据返回值改router应该怎么做?
this.$http(...).then(reponse=>{
this.$router.go({'/link-to-go'})
});
我发现结果没动,页面刷新了一下,表单被重置了,但没有跳转到link-to-go,而使用this.$router.push就可以
请问这两者的区别和应用环境
解决方案
如果是vue2
router.go(n)
这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n)
router.push(location)
想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。
router.replace(location)
跟 router.push 很像,唯一的不同就是,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录。
这篇关于vue.js - this.$router.go() vs this.$router.push()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文