问题描述:
在使用vue-router跳转过来的页面中内嵌了一个iframe,通过选择不同项替换iframe的src,但是在使用this.$router.go(-1)返回之前的页面时发现页面刷新,点击多次才能返回之前的页面
原因:
浏览器机制的原因,在 iframe 导航变化后手动点击浏览器的后退按钮也依然只是后退 iframe 中的导航。类似window.history.go
解决方法:
iframe 里面的链接用 location.replace 跳转,这样就只会有一个历史记录了
<iframe ref="iframe"></iframe>
this.$refs.iframe.contentWindow.location.replace(src)