vue Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘comcode‘)

vue Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘comcode‘)

 在查看信息时,界面没反应,然后查看控制台报错

index.vue?t=1680763420735:497 Uncaught (in promise) TypeError: 
Cannot read properties of undefined (reading '***code')

然后查找获取数据的方法

  getInfo(row.id).then((response) => {
    info.value = response.data ;
  });

 f12查看返回数据信息如下:

{msg: "操作成功", code: 200}

因为没有正确返回数据,导致获取response.data时是一个undefined ,因此展示数据的时候就会出错

{{ info.***code}}

所以修改获取数据的function,然后将获取的数据判断一下,如果为undefined,则赋值一个新对象,否则从data中获取数据

  getInfo(row.id).then((response) => {
		info.value = response.data === undefined ? {} : response.data;
	});

转载请说明出处内容投诉
CSS教程_站长资源网 » vue Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘comcode‘)

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买