vue-cli 3、4 (vue-element-tmplate) 兼容ie11

1. SCRIPT438: 对象不支持“call”属性或方法错误

1. 修改babel配置
// bablel.config.js
module.exports = {
  presets: [
    ['@vue/app', {
      useBuiltIns: 'entry',
      polyfills: [
        'es6.regexp'
      ]
    }]
  ]
}
2.安装@babel/polyfill
// bash
npm i @babel/polyfill -S
3.使用@babel/polyfill,main.js顶部引入
// main.js
import '@babel/polyfill'

2. vue-router的hash路由,router-link跳转页面不生效

监听hashchange事件,使用$router.push跳转

// App.vue
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',
        () => {
          const currentPath = window.location.hash.slice(1)
          if (this.$route.path !== currentPath) {
            this.$router.push(currentPath)
          }
        },
        false
      )
    }
  }
}

你可能感兴趣的:(vue)