步骤1:

# 通过 npm 安装小程序所需的 polyfill 库
npm install mphttpx

步骤2:

// 通过 mphttpx 引入小程序所需的 TextDecoder
import { TextDecoder } from "mphttpx";

步骤3:

// 编写具体的业务代码,例如:
const utf8decoder = new TextDecoder(); // default 'utf-8'
const encodedText = new Uint8Array([240, 160, 174, 183]);
console.log(utf8decoder.decode(encodedText)); // 𠮷

注意事项:小程序中使用npm安装第三方包前,请先阅读小程序文档npm支持。

更多推荐