只要在后面加上.catch((e) => {}),就不會報錯了,
const queGetdata = (params, context) => {
return new Promise((resolve, reject) => {
appVue.$http.post(appVue.$apis.getdata,
{
gcode: 'QUERY_CUSTBILL'
}, {
isAutoLoading: false, //是否展示loading
}).then(resp => {
console.log("觸發(fā)進來了222222")
let data = resp.responseBody.paramdata;
console.log("觸發(fā)進來了"+JSON.stringify(data[0]))
// commit必須放在后面,不然會報錯“Uncaught (in promise) TypeError: Cannot read properties of undefined (readin”
context.commit("setCustbill", JSON.parse(JSON.stringify(data[0])))
console.log("觸發(fā)data[0]"+JSON.stringify(data[0]))
resolve(data[0])
}).catch(error => {
reject(error) // 這里報error寫進去就不會報錯,注意注意 Uncaught (in promise)
});
})
}
?
文章來源:http://www.zghlxwxcb.cn/news/detail-699911.html
?這個問題的解決要想resolve(),在commit()不然就會報錯,注意:先后的順序文章來源地址http://www.zghlxwxcb.cn/news/detail-699911.html
const queGetdata = (params, context) => {
return new Promise((resolve, reject) => {
appVue.$http.post(appVue.$apis.getdata,
{
gcode: 'QUERY_CUSTBILL'
}, {
isAutoLoading: false, //是否展示loading
}).then(resp => {
console.log("觸發(fā)進來了222222")
let data = resp.responseBody.paramdata;
console.log("觸發(fā)進來了"+JSON.stringify(data[0]))
resolve(data[0])
// commit必須放在后面,不然會報錯“Uncaught (in promise) TypeError: Cannot read properties of undefined (readin”
context.commit("setCustbill", JSON.parse(JSON.stringify(data[0])))
console.log("觸發(fā)data[0]"+JSON.stringify(data[0]))
}).catch(error => {
reject(error)
});
})
}
到了這里,關(guān)于Uncaught (in promise)和Uncaught (in promise) TypeError: Cannot read properties of undefined (readin的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!