在React Native中,我想对URLSearchParams进行抽象,所以我编写了这个类:
export class HttpSearchParamsAdapter extends URLSearchParams implements HttpSearchParams {
constructor() {
super();
}
set(param: string, val: string): void {
super.set(param, val);
}
}但是当我构建应用程序时,我遇到了这个错误: Can't find variable: URLSearchParams。我使用来自es6的URLSearchParams。
发布于 2019-01-04 17:01:01
正如mrgoos所说,在使用JavaScript Core的iOS中不支持URLSearchParams,你可以添加一个polyfill到React Native。
例如,我在使用wretch时遇到了问题,所以我全局使用了这个polyfill:url-search-params-polyfill
// index.js
import 'url-search-params-polyfill';更新(用于React Native 0.59)
在React Native 0.59中,开发人员使用throw new Error('not implemented');“实现”了URLSearchParams的一些方法,因此...它不幸地失败了。
你可以在这里阅读这个问题:https://github.com/facebook/react-native/issues/23922
我们可以使用whatwg-url实现和buffer包来代替我使用的polyfill,如下所示:https://github.com/facebook/react-native/issues/23922#issuecomment-476070032
// index.js
import { URL, URLSearchParams } from 'whatwg-url';
import { Buffer } from 'buffer';
// react-native 0.59 added its own global URLSearchParams without implementation...
// https://github.com/facebook/react-native/blob/e6057095adfdc77ccbbff1c97b1e86b06dae340b/Libraries/Blob/URL.js#L66
// Issue: https://github.com/facebook/react-native/issues/23922
global.Buffer = Buffer;
global.URL = URL;
global.URLSearchParams = URLSearchParams;发布于 2017-06-19 22:04:17
iOS中不支持URLSearchParams。https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
https://stackoverflow.com/questions/43298987
复制相似问题