1、安装babel-polyfill
命令:npm i --save-dev babel-polyfill在入口文件main.js中引入 :import ‘babel-polyfill’在build文件夹下找到webpack.base.conf.js.修改入口方式:
entry: { app:['babel-polyfill','./src/main.js'] },
2、安装babel-preset-es2015(解决ES6/ES7高级语法兼容)
npm install --save-dev babel-preset-es2015-ie调整根目录下.babelrc内容(如果根目录下缺少文件.babelrc,新建一个)
{ "presets": [ "es2015", ["env", { "targets": { "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] } }], "stage-2" ], "plugins": ["transform-vue-jsx", "transform-runtime"], "env": { "test": { "presets": ["env", "stage-2"], "plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"] } }}
3. index.html添加meta标签
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="renderer" content="webkit">
4. 配置完上述三步后,可能还有依赖的三方组件中存在不兼容的es6、es7语法(可以根据浏览器控制台报错,定位对应的文件)
{ test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test'),resolve('static'),resolve('node_modules/webpack-dev-server/client'),,resolve('node_modules/element-ui/src')] }
配置完IE、360等浏览器就可以展示页面了。