[vue] 嵌套iframe,$router.go(-1)后退bug

问题:更改iframe中src值后导致的路由跳转混乱,多次更改iframe的src属性后,调用router.go(-1),不能实现路由后退上一级
原因:还是在于通过ifream.src赋值,因为域相同,还是会向window.history中插入一条历史记录

之前的代码

<iframe ref="iframe" :src="url" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
<script>
  export default {
    methods:{
      setIframeSrc(){
        this.url = '新url'
      }
    }
  }  
</script>

解决办法

去掉:src="url" ,增加this.$refs.iframe.contentWindow.location.replace

<iframe ref="iframe" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
<script>
  export default {
    methods:{
      setIframeSrc(){
      	this.url = '新url'
        this.$refs.iframe.contentWindow.location.replace(this.url)
      }
    }
  }  
</script>


参考:

嵌套iframe,$router.go(-1)后退bug

你可能感兴趣的:(#,vue,vue.js,golang,bug)