vue兼容IE浏览器

749 阅读1分钟

用vue2开发项目时,项目要求兼容ie。在网上找了很多参考,总结了以下几个配置。

  1. 首先安装 babel-polyfill,es6-promise。在入口文件main.js中配置。这一部分要放在顶部,我尝试了一下放在下面在ie模式页面会加载不出来。 image.png
    import 'babel-polyfill'
    import Es6Promise from 'es6-promise'
    require('es6-promise').polyfill()
    Es6Promise.polyfill()
  1. 配置babel.config.js

image.png

    presets: [
    [
      "@vue/app",
      {
        "useBuiltIns": "entry",
        polyfills: [
          'es6.promise',
          'es6.symbol'
        ]
      }
    ]
    ]
  1. 配置vue.config.js,加上下面这两个配置。 image.png
   transpileDependencies:['*'],
   chainWebpack: config => {
    config.entry.app = ['babel-polyfill', './src/main.js'];
  },

4 .browserslistrc 中配置,如果不做以下配置,页面会加载不出来。我尝试了修改 not ie < 11 ,使用360急速浏览器兼容模式,ie9,ie10,也都好使。

    > 1%
    last 2 versions
    not ie < 11