httpRequest.js:87 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'status') at eval (httpRequest.js:87:1)
时间: 2023-08-26 10:12:42 浏览: 41
这个错误信息通常表示在 Promise 对象中的某个属性未被正确定义,导致无法读取该属性的值。出现这种情况的原因可能包括请求返回值为空或者请求返回值的格式与期望不符。建议您检查代码中与该错误相关的部分,例如 Promise 对象的定义、请求返回值的处理等,并确保这些部分的逻辑正确性和完整性。您也可以尝试使用浏览器的开发者工具进行调试,以便更好地定位问题所在。
相关问题
Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'loading')
Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'loading')是一个常见的错误,它通常表示在promise中设置了一个undefined的属性。根据引用中提到的解决方法,这个错误很可能是因为在网络请求的异步代码块中,this的作用域与当前数据所在类的this不同。
使用箭头函数或在后方加上bind(this)可以解决这个问题。箭头函数会继承外部的this值,因此在箭头函数中使用this时,它会沿着传递链一直向上找到实际的this。所以,你可以将httpRequest方法中的第二个.then()回调函数改为箭头函数,或者在该函数后加上.bind(this)。这样可以确保this指向正确的作用域,避免出现undefined的错误。
修改后的代码如下所示:
```javascript
httpRequest () {
fetch('https://jsonplaceholder.typicode.com/posts')
.then(function (response) {
return response.json()
})
.then((data) => {
this.posts = data
console.log(this.posts)
})
}
```
通过这样的修改,你应该能够避免Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'loading')错误的出现。希望这个解决方法能够帮到你。如果还有其他问题,请随时提问。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [ASP.NET MVC运行出现Uncaught TypeError: Cannot set property __MVC_FormValidation of null的解决方法](https://download.csdn.net/download/weixin_38731761/13069683)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [vue出现 Uncaught (in promise) TypeError: Cannot set property posts of undefined at eval](https://blog.csdn.net/sinat_27798375/article/details/106225679)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
C:\Users\Administrator\Desktop\CheckNSFW\node_modules\node-fetch\lib\index.js:1327 throw new TypeError('Only absolute URLs are supported'); ^ TypeError: Only absolute URLs are supported at getNodeRequestOptions (C:\Users\Administrator\Desktop\CheckNSFW\node_modules\node-fetch\lib\index.js:1327:9) at C:\Users\Administrator\Desktop\CheckNSFW\node_modules\node-fetch\lib\index.js:1454:19 at new Promise (<anonymous>) at fetch (C:\Users\Administrator\Desktop\CheckNSFW\node_modules\node-fetch\lib\index.js:1451:9) at HTTPRequest.PlatformNode.fetch (C:\Users\Administrator\Desktop\CheckNSFW\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:7430:16) at HTTPRequest.<anonymous> (C:\Users\Administrator\Desktop\CheckNSFW\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:8289:55) at step (C:\Users\Administrator\Desktop\CheckNSFW\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:125:27) at Object.next (C:\Users\Administrator\Desktop\CheckNSFW\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:74:53) at C:\Users\Administrator\Desktop\CheckNSFW\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:67:71 at new Promise (<anonymous>)
这个错误是由于在使用 `node-fetch` 库发起 HTTP 请求时,传递的 URL 不是绝对 URL 导致的。
确保您传递给 `node-fetch` 的 URL 是一个绝对 URL,以便正确发起请求。绝对 URL 包含完整的协议(例如 `http://` 或 `https://`)和主机名(例如 `example.com`)。
请检查您的代码中的 URL,确保它是绝对 URL,并且不含有任何错误或缺失部分。如果您可以提供更多的代码和上下文信息,我可以帮助您进一步排查问题。