vue项目中在ie浏览器中iframe引入情况下无法跳转问题解决方法

303 阅读1分钟

在main.js中添加mounted函数,在函数中判断浏览器是否为IE

mounted () {
  // 判断浏览器是否为IE
  const isIE = (
    /MSIE (\d+\.\d+);/.test(navigator.userAgent) || ~navigator.userAgent.indexOf('Trident/')
  )

  // 兼容ie iframe切换路由不生效
  if (isIE) {
    window.addEventListener(
      'hashchange',
      () => {
        var currentPath = window.location.hash.slice(1)
        if (this.$route.path !== currentPath) {
          this.$router.push(currentPath)
        }
      },
      false
    )
  }
}