0
我越来越等待 - catch错误 - UnhandledPromiseRejectionWarning
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 44): Error: fail
main.js
import { request } from './api'
async getData({ commit, state }, ids){
try {
var x = await request(ids)
commit('getData', x.data)
} catch (e) {
console.log('request failed get',e.code,e.errno)
}
}
api.js
export async function request(type,url,ids){
axios.get('localhost/data')
.then(function (response) {
return Promise.resolve(response.data)
})
.catch(function (e) {
return Promise.reject(new Error('fail'))
})
}
我如何处理的承诺拒绝? try catch块不应该从await函数中捕获错误吗?
感谢,我只注意到我忘了复位功能 - 好吧,我想我明白了,我回一个承诺中承诺这是没用的 – user345234674567