vue 之this.$router.push、replace、go的区别
<p><span style="font-size: 16px">一、this.$router.push</span></p><p><span style="font-size: 16px">说明:跳转到指定URL,向history栈添加一个新的记录,点击后退会返回至上一个页面</span></p>
<p><span style="font-size: 16px">使用:</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">this.$router.push('/index')
this.$router.push({path:'/index'})
this.$router.push({path:'/index',query:{name: '123'}})
this.$router.push({name:'index',params:{name:'123'}})
</pre>
</div>
<p> </p>
<p><span style="font-size: 16px">二、this.$router.replace</span></p>
<p><span style="font-size: 16px">说明:跳转到指定URL,替换history栈中最后一个记录,点击后退会返回至上上一个页面</span></p>
<p><span style="font-size: 16px">使用:同push</span></p>
<p> </p>
<p><span style="font-size: 16px">三、this.$router.go(n)</span></p>
<p><span style="font-size: 16px">说明:类似window.history.go(n),向前或向后跳转n个页面,n可正(先后跳转)可负(向前跳转)</span></p>
<p><span style="font-size: 16px">使用:</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">this.$router.go(1) //类似history.forward()
this.$router.go(-1) //类似history.back()
</pre>
</div>
<p> </p>
<p> </p><br><br>
来源:https://www.cnblogs.com/corgisyj/p/11352862.html
頁:
[1]