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

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

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

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';

.....

回答

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

// vue.config.js

chainWebpack: (config) => {

// 在chainWebpack中添加下面的代码

config.entry('main').add('babel-polyfill'); // main是入口js文件

},

以上是 Vue项目无法在IE中运行,已安装babel 的全部内容, 来源链接: utcz.com/a/78270.html

回到顶部