Cannot read property ‘then‘ of undefined
程序员文章站
2022-07-03 10:32:52
...
解决了使用Promise时控制台报错“Cannot read property ‘then’ of undefined”
原因:没有return new Promise
解决方法:加上return就解决了这个问题
const request = (options) => {
return new Promise((resolve, reject) => {
// code ...
});
});
*代码风格问题
项目中使用了eslint,不可以在箭头函数后面直接写return,会出现如下报错:
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>
(释义:箭头主体周围出现意外的块语句; 在 =>
之后立即移动返回值)
解决方法:箭头函数改成function的写法就可以了
const request = function (options) {
return new Promise((resolve, reject) => {
// code ...
});
});
上一篇: 美呆了 最全的拍照技巧汇总
下一篇: 适合新手:生活取景+摄影构图小技巧
推荐阅读
-
Cannot access protected property validate $scene
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
npm ERR! Cannot read property 'path' of null
-
js报错 Cannot read property 'getAttribute' of null
-
[VUE ERROR] Error in render: "TypeError: Cannot create property 'header' on boolean 'true'"
-
微信小程序报Cannot read property 'setData' of undefined的错误
-
webpack报错Cannot read property 'presetToOptions' of undefined
-
Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
-
JavaScript Uncaught TypeError: Cannot read property 'value' of null
-
cvc-elt.1: Cannot find the declaration of element 'beans'Failed to read schema document 'http://www.springframework.org/schema/beans/sprin