Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

Vue项目无法在IE中运行,已安装babel

我的项目用IE运行报错,是ie不支持es6的原因。然后我安装了babel,但是没有生效无法运行,尝试了很多方法都不行,救救孩子吧。
vue版本:2.6.1
vue cli版本:4.5.6

IE控制台
image.png
image.png

babel.config.js文件:

module.exports = {
  presets: [
    [
      '@vue/app',
      {
        useBuiltIns: 'entry'
      }
    ],
  ],
  plugins: [
    [
      'import',
      {
        libraryName: 'vant',
        libraryDirectory: 'es',
        style: true
      },
      'vant'
    ]
  ]
};

.browserslistrc文件:

> 1%
last 2 versions
IE 11

package.json文件:

{
  "name": "goodsmanagerapp",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "@babel/polyfill": "^7.12.1",
    "axios": "^0.20.0",
    "core-js": "^3.8.1",
    "vant": "^2.10.8",
    "vue": "^2.6.11",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.12.10",
    "@babel/core": "^7.12.10",
    "@babel/plugin-transform-arrow-functions": "^7.12.1",
    "@babel/preset-env": "^7.12.10",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "babel-plugin-import": "^1.13.0",
    "css-loader": "^4.3.0",
    "es6-promise": "^4.2.8",
    "vue-template-compiler": "^2.6.11"
  }
}

vue.config.js文件:

module.exports = {
  runtimeCompiler: true,
  publicPath: '/Content/app',
  devServer: {
    disableHostCheck: true
  }, css: {
    extract: false,
    sourceMap: true
  },
  transpileDependencies: ['*'],
  chainWebpack: config => {
    config.entry('main').add('@babel/polyfill');
  }
}

main.js :引入了babel

import '@babel/polyfill';
import Es6Promise from 'es6-promise'
Es6Promise.polyfill()
import 'core-js/stable'; import 'regenerator-runtime/runtime';
.....

更新:现在没有报错但是仍然白屏,更诡异的是ie9可以运行,10和11不可以


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

上面es6-promise是比较旧的,可以试下babel-polyfill

// vue.config.js
chainWebpack: (config) => {
  // 在chainWebpack中添加下面的代码
  config.entry('main').add('babel-polyfill'); // main是入口js文件
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...