Uncaught (in promise)和Uncaught (in promise) TypeError: Cannot read properties of undefined (readin

只要在后面加上.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("触发进来了222222")
			let data = resp.responseBody.paramdata; 
			console.log("触发进来了"+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("触发data[0]"+JSON.stringify(data[0]))
			resolve(data[0])
			
		}).catch(error => {
			reject(error)  // 这里报error写进去就不会报错,注意注意 Uncaught (in promise)
		});
	})
}

 

 这个问题的解决要想resolve(),在commit()不然就会报错,注意:先后的顺序

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("触发进来了222222")
			let data = resp.responseBody.paramdata; 
			console.log("触发进来了"+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("触发data[0]"+JSON.stringify(data[0]))
			
			
		}).catch(error => {
			reject(error)
		});
	})
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值