vue2 vue-router 在IE下不跳转问题

446 阅读1分钟

问题

使用vue-router 在IE下 a标签里的路由不跳转,火狐,chrome工作正常。

解决方式:

在App.vue 里增加判断IE浏览器手动修复……
修改代码如下:
src/App.vue
<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: "App",
  mounted() {
    function checkIE() {
      return (
        "-ms-scroll-limit" in document.documentElement.style &&
        "-ms-ime-align" in document.documentElement.style
      );
    }
    if (checkIE()) {
      window.addEventListener(
        "hashchange",
        () => {
          var currentPath = window.location.hash.slice(1);
          if (this.$route.path !== currentPath) {
            this.$router.push(currentPath);
            // this.$router.replace(currentPath)

          }
        },
        false
      );
    }
  }
};
</script>

本文转载于menphis.blog.csdn.net/article/det…