【发布时间】:2019-11-03 07:16:55
【问题描述】:
我花了几天时间设置一个 vue.js + vue-cli + typescript + vuetify 项目以在 IE 11 上运行但没有成功?
我在网上找到了许多解释应该如何完成但没有成功的帖子。我试图以几乎所有可能的方式组合下面解释的设置但没有成功,以许多不同的错误结束,直到空白页
应用程序在 Chrome 或 FF 上运行良好
如果有人在 IE 11 中运行这样的应用程序,将不胜感激
上下文(所有最新版本):
- vue-cli
- 打字稿
- vue.js + vue-router + vuex + vuex-persistedstate
- vuetify + vue-i18n + vuelidate
- axios
如果有些问题看起来很愚蠢,请原谅我,因为我是 babel/webpack 开发的新手..
我的尝试和问题: (我已经尝试了以下几乎所有的组合)
- 我应该按照vuetify setup for IE 11 here 中的说明使用
npm install babel-polyfill --save吗? - 我应该按照vuetify setup for IE 11 here 中的说明添加
import 'babel-polyfill'inmain.ts吗? - 或者我应该加
import '@babel/polyfill'inmain.tsas explained here - 我应该按照vuetify setup for IE 11 here 中的说明使用
npm install @babel/preset-env --save-dev,还是因为使用了vue-cli而没有必要? -
在
babel.config.js,我应该替换vue-cli最初创建的内容presets: [ '@vue/app' ]presets: ['@babel/preset-env']或者(在很多地方都可以看到)?
presets: [['@vue/app', useBuiltIns: 'entry' }]]或添加 2 个预设?
presets: [ ['@babel/preset-env'], ['@vue/app', useBuiltIns: 'entry' }] ]我应该添加一些像explained here这样的插件吗?
presets: ['@vue/app'], plugins: ['@babel/transform-modules-commonjs']还是改成这样as explained in the vue doc here?
presets: [ ['@vue/app', { polyfills: [ 'es6.promise', 'es6.symbol' ] }] ] -
在
vue.config.js,我应该添加吗?transpileDependencies: [ 'vuetify', 'vue-i18n', 'vuelidate', 'axios' ]
[解决方案 2019-06-25]
我们终于让它工作了,@blackening 的回答非常有帮助
还发生了我们在 IE 11 中使用 google"reCaptcha" 的 javsacript 错误,在以下设置后消失了:
作为先决条件,安装vue-cli并通过选择`'Use Babel and TypeScript for auto-detected polyfills'来创建项目
1) 安装core-js@3
npm install core-js@3
2) 编辑main.ts像这样:
import 'core-js/stable'
import Vue from 'vue'
import '@/plugins/vuetify'
{...}
3) 编辑babel.config.js
module.exports = {
presets: [
['@vue/app', { useBuiltIns: 'entry' }]
]
}
就是这样!
现在我们正在使用 IE 11 CSS,但这是一个已知的故事......例如,在vue 中仅将样式应用于 IE,只需像这样编写代码
<style scoped>
/* Only for IE 11, wrap div text */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.ieMaxWidth90 {
max-width: 90vw; /* 90% view width */
}
}
</style>
【问题讨论】:
-
仅供参考:我没有包含 es6 生成器支持。假设你需要在core-js导入下添加
import 'regenerator-runtime/runtime';。
标签: vue.js internet-explorer-11 vuetify.js vue-cli-3