我正在使用fetch,并且已经在我的应用程序中包含了whatwg-fetch。
我还使用了杰克·阿奇博尔德的博客That's so fetch!中描述的TextDecoder来解码响应,但我不确定要使用哪种polyfill。
(目前Safari抱怨ReferenceError: Can't find variable: TextDecoder)
我猜有一个用于TextDecoder的polyfill,但我找不到它...
发布于 2016-11-18 03:52:26
我能够通过使用text-encoding库来解决这个问题
npm install text-encoding --save与
import encoding from 'text-encoding';
const decoder = new encoding.TextDecoder();发布于 2017-10-04 00:21:07
对于快速客户端测试(不使用NPM):
<script src="https://unpkg.com/text-encoding@0.6.4/lib/encoding-indexes.js"></script>
<script src="https://unpkg.com/text-encoding@0.6.4/lib/encoding.js"></script>..and然后像正常一样使用TextDecoder。MDN's example:
var win1251decoder = new TextDecoder('windows-1251');
var bytes = new Uint8Array([207, 240, 232, 226, 229, 242, 44, 32, 236, 232, 240, 33]);
console.log(win1251decoder.decode(bytes)); // Привет, мир!<script src="https://unpkg.com/text-encoding@0.6.4/lib/encoding-indexes.js"></script>
<script src="https://unpkg.com/text-encoding@0.6.4/lib/encoding.js"></script>
发布于 2019-12-05 12:38:52
现在,您可以使用MDN website推荐的FastestSmallestTextEncoderDecoder polyfill (1.5KB)。
https://stackoverflow.com/questions/40662142
复制相似问题