2016-11-17 28 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>