【发布时间】:2020-05-14 07:11:18
【问题描述】:
我在让我的 polyfill 在 Edge 中工作时遇到了巨大的麻烦。我试图按照文档进行各种尝试,但都不起作用。这似乎是promise.finally,具体来说这是行不通的。这发生在 vuex 模块中,所以我尝试将 vuex 添加到 vue.config 中的 transpileDependencies 但没有运气。
我的 babel.config.js:
module.exports = {
presets: [['@vue/cli-plugin-babel/preset', {
useBuiltIns: 'entry',
}]],
};
在我的 main.js 中,我在最顶部有以下两个导入:
import 'core-js/stable';
import 'regenerator-runtime/runtime';
我的 vue.config.js
// eslint-disable-next-line import/no-extraneous-dependencies
const webpack = require('webpack');
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
configureWebpack: {
// Set up all the aliases we use in our app.
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 6,
}),
],
},
css: {
// Enable CSS source maps.
sourceMap: !isProd,
},
transpileDependencies: ['vuex'],
};
请注意,如上所述,我尝试了使用和不使用 transpileDepedencies。它在这里说 vue/babel-preset-app es7.promise.finally 作为默认 polyfill 包含在内
版本:
- Microsoft Edge:44.18
- Microsoft EdgeHTML 18.18362
- @vue/cli-plugin-babel": "^4.1.2"
- “core-js”:“^3.6.4”
- “再生器运行时”:“^0.13.3”
13/02 更新
所以我尝试在我的网站上的边缘键入 Promise.prototype,它确实显示为 polyfill:
所以目前我正在调查我的链(axios/vue axios)的某些部分是否没有返回承诺。由于它在 chrome 中工作,我怀疑链的一部分没有正确填充?
这是我的整个链条:
/* VUEX MODULE ACTION */
[a.ALL_CUSTOMERS](context) {
context.commit(m.SET_CUSTOMER_LOADING, true);
CustomerService.getAll()
.then(({ data }) => {
context.commit(m.SET_CUSTOMERS, data);
})
.finally(() => context.commit(m.SET_CUSTOMER_LOADING, false));
},
/* CUSTOMER SERVICE */
import ApiService from '@/common/api.service';
const CustomerService = {
getAll() {
const resource = 'customers/';
return ApiService.get(resource);
},
...
}
/* API SERVICE */
import Vue from 'vue';
import axios from 'axios';
import VueAxios from 'vue-axios';
const ApiService = {
init() {
Vue.use(VueAxios, axios);
let baseUrl = process.env.VUE_APP_APIURL;
Vue.axios.defaults.baseURL = baseUrl;
},
setHeader() {
Vue.axios.defaults.headers.common.Authorization = `Bearer ${getToken()}`;
},
get(resource) {
this.setHeader();
return Vue.axios.get(`${resource}`);
},
...
}
【问题讨论】:
-
有趣,Edge 不需要 polyfill,因为它支持
finally()on Promise 从 v18 开始 -
出于好奇,EdgeHTML 版本是什么?您可以在 Edge 版本的下方找到它。我问是因为 CanIUse 支持这一点。从他们的网站:
*Version number used for Edge is based on the number of EdgeHTML rather than Edge itself. This is because EdgeHTML is the engine for Edge that is related to feature support change. -
Microsoft EdgeHTML 18.18362
-
Edge 应该告诉你这是一个承诺。而是说它是一个对象。所以返回的对象不是预期的承诺。
-
这个问题可以通过提供一个简化的 repo 来重现问题,以便其他人可以提供帮助。像codesandbox.io 这样的网站可以用于此目的。
标签: javascript vue.js vuejs2 babeljs polyfills