【发布时间】:2018-04-01 15:11:36
【问题描述】:
我明白了
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 函数中捕获错误吗?
【问题讨论】:
标签: es6-promise ecmascript-2017