试图在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);
});有什么想法吗?
发布于 2018-06-26 10:52:16
这是因为您的http://localhost:8092在您的桌面上被正确解析(假设为127.0.0.1),但是对于移动设备- localhost是这个特定的设备,而不是您的桌面。因此,我想您应该尝试使用可以通过您的所有网络访问的ip地址(而不仅仅是localhost),前提是您的移动设备连接到同一个网络。
https://stackoverflow.com/questions/51040004
复制相似问题