【发布时间】:2018-06-26 09:56:52
【问题描述】:
试图让 fetch 在 ios/android(chrome 和 safari)上工作。 我目前在我的 webpack 中有这个(使用 webpack 4):
new webpack.ProvidePlugin({
Promise: 'imports-loader?this=>global!exports-loader?global.Promise!es6-promise',
fetch: 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch'
}),
使用此代码,它适用于 IE 桌面,但在我的 android 上,它会出现以下错误:
Uncaught (in promise) TypeError: Failed to fetch
获取代码:
fetch('http://localhost:8092/api/shops/search?searchString=spicy')
.then(function(response) {
if (response.status >= 400) {
throw new Error("Bad response from server");
}
return response.json();
})
.then(function(stories) {
console.log('hej', stories);
});
有什么想法吗?
【问题讨论】:
标签: javascript reactjs webpack fetch polyfills