Open massive688 opened 3 years ago
修改https://github.com/nuysoft/Mock/blob/refactoring/src/mock/xhr/xhr.js 291-300行
that.custom.options.headers = that.custom.requestHeaders let promise = convert(that.custom.template, that.custom.options) if (typeof promise.then === 'function') { promise.then(resp=>{ // fix #92 #93 by @qddegtya that.response = that.responseText = JSON.stringify(resp,null, 4) that.readyState = MockXMLHttpRequest.DONE that.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ )) that.dispatchEvent(new Event('load' /*, false, false, that*/ )); that.dispatchEvent(new Event('loadend' /*, false, false, that*/ )); }) } else { // fix #92 #93 by @qddegtya that.response = that.responseText = JSON.stringify(promise,null, 4) that.readyState = MockXMLHttpRequest.DONE that.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ )) that.dispatchEvent(new Event('load' /*, false, false, that*/ )); that.dispatchEvent(new Event('loadend' /*, false, false, that*/ )); }
搞个 PR
解决Mock.mock()中不能使用Promise和异步函数async的问题。 Addresses an issue where Promise and the asynchronous function async cannot be used in Mock.mock(). 你可以下载: You can download:
npm i mockjs-pro
https://www.npmjs.com/package/mockjs-pro?activeTab=readme
修改https://github.com/nuysoft/Mock/blob/refactoring/src/mock/xhr/xhr.js 291-300行