2016-11-17 132 views

回答

5

我能够通过使用text-encoding来解决这个问题库

npm install text-encoding --save 

随着

import encoding from 'text-encoding'; 
const decoder = new encoding.TextDecoder(); 
+0

只是解码的文件我要补充? encoding.js或encoding-indexes.js ??在添加后有必要使用“从'text-encoding'导入编码';'这条线? –

+0

如何验证polyfill工作正常? –

1

为了快速客户端测试(无NPM):

<script src="https://unpkg.com/[email protected]/lib/encoding-indexes.js"></script> 
<script src="https://unpkg.com/[email protected]/lib/encoding.js"></script> 

..和然后使用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/[email protected]/lib/encoding-indexes.js"></script> 
 
<script src="https://unpkg.com/[email protected]/lib/encoding.js"></script>

相关问题