WishMeLz

生活其实很有趣

移动端 pdfh5 预览pdf

import pdfh5 from "pdfh5";
import "pdfh5/css/pdfh5.css";
let pdfH5Res = new pdfh5("#signpdf", {
     pdfurl: resUrl,
     responseType: "blob",
 });

报错异常

The `Array.prototype` contains unexpected enumerable properties: hasItem, removeItem; thus breaking e.g. `for...in` iteration of `Array`s

2024-03-21T12:11:41.png

大概因为数组原型上的方法做了检测 不能添加除原始属性上的其他属性。

 let _unexpectedProperties = [], _logArr = [];
          for (let key in Array.prototype) {
            if (!Array.prototype.hasOwnProperty(key)) continue;
            // 存放直接属性
            _unexpectedProperties.push(key);
          };
          // 存放原始键 原始方法
          _logArr = _unexpectedProperties.map(v => ({ [v]: Array.prototype[v] }));
          // 删除直接属性
          _unexpectedProperties.forEach(v => delete Array.prototype[v]);
          let pdfH5Res = new pdfh5("#signpdf", {
            pdfurl: resUrl,
            responseType: "blob",
          });
          pdfH5Res.on('complete', function (status, msg, time) { 
            // Object.assign(Array.prototype, ..._logArr);
            console.log("状态:" + status + ",信息:" + msg + ",耗时:" + time + "毫秒,总页数:" + this.totalNum)
          })