vue报错解决:Error in v-on handler (Promiseasync) “TypeError Cannot read properties ofundefined

报错信息:[Vue warn]: Error in v-on handler (Promise/async): "TypeError: Cannot read properties of undefined (reading 'code ')” axios可以获取数据,控制台输出为undefined
vue报错解决:Error in v-on handler (Promiseasync) “TypeError Cannot read properties ofundefined_第1张图片
报错代码:
vue报错解决:Error in v-on handler (Promiseasync) “TypeError Cannot read properties ofundefined_第2张图片
错误原因:在①或者②的axios请求时,请求结果被catch捕获,所以axios可以获取到数据,但在catch中的res此时是未赋值的,所以控制台在③处调用res.xxx会出现报错
解决方法:只需要在catch中将axios获取到的数据赋值给res即可

修改后:

vue报错解决:Error in v-on handler (Promiseasync) “TypeError Cannot read properties ofundefined_第3张图片

你可能感兴趣的:(前端,html,vue.js,前端,javascript)