简体   繁体   English

Promise.then 不是仅在服务器上的函数错误

[英]Promise.then is not a function error only on server

I am running the below code on local which is working fine but on server I have this error:我在本地运行以下代码,运行正常,但在服务器上出现此错误:

Promise.then is not a function Promise.then 不是函数

let promise = null;
  if (this.fileUrl) {
    promise = this.pdfJS.getDocument(this.fileUrl);
  }
  else if (this.base64FileData) {
    const pdfData = atob(this.base64FileData);
    promise = this.pdfJS.getDocument({ data: pdfData });
  }
  console.log('pretty');
  console.log(promise);
  
  promise.then(function (docObj) {
    console.log('promistest');
    console.log(docObj);
    this._loadingEnd();
    this.renderPages(docObj);
  }, this._onDocumentLoadError.bind(this)
);

The object returned by .getDocument is not a promise, but it has a property called promise .getDocument返回的对象不是promise,但它有一个名为promise的属性

therefore所以

let promise;
if (this.fileUrl) {
    promise = this.pdfJS.getDocument(this.fileUrl).promise;
} else if (this.base64FileData) {
    const pdfData = atob(this.base64FileData);
    promise = this.pdfJS.getDocument({ data: pdfData }).promise;
} else {
    promise = Promise.reject('invalid state');
    // this will be handled by `this._onDocumentLoadError.bind(this)`
}
console.log('pretty');
console.log(promise);
promise.then(function (docObj) {
    console.log('promistest');
    console.log(docObj);
    this._loadingEnd();
    this.renderPages(docObj);
}, this._onDocumentLoadError.bind(this));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM