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 'comcode')

然后查找获取数据的方法

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

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

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

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

{
   
   { info.comcode}}

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

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

猜你喜欢

转载自blog.csdn.net/jungeCSND/article/details/130059965