呈现错误:"TypeError:无法读取未定义的属性'名称'" (Vue) [英] Error in render: "TypeError: Cannot read property 'name' of undefined" (Vue)

查看:1759
本文介绍了呈现错误:"TypeError:无法读取未定义的属性'名称'" (Vue)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是使用诸如vuex之类的状态管理来了解vuejs.

i just learn about vuejs using state management like vuex.

我收到此错误

渲染错误:"TypeError:无法读取未定义的属性'name'"

Error in render: "TypeError: Cannot read property 'name' of undefined"

当我像这样从服务器填充数据时:

when i populate my data from server like this :

authenticated:{
  created_at:"2019-12-13 16:04:47"
  email:"super@vetura.id"
  email_verified_at:"2019-12-13 16:04:47"
  employee:{
    accountNumber:null
    address:"JL.VETERAN UTARA LR.124 NO.1"
    baseSalary:"10000000.000000"
    birthDate:"1987-09-14"
    birthPlace:"Ujung Pandang"
    category_id:null
    classification_id:null
    code:"000001"
    created_at:"2019-12-13 16:04:47"
    dateJoin:"2012-01-04"
    dateResign:null
    department_id:null
    division_id:null
    gender:null
    group_id:null
    height:172
    id:1
    idCardNumber:null
    kecamatan:null
    kelurahan:null
  }
  employee_id:1
  id:1
  role:"0"
  updated_at:"2019-12-15 14:22:26"
}

实际上,数据响应可以显示在模板上,当我尝试填充authenticated.employee.name时,控制台会向我显示错误,但可以显示数据.

Actually, the data response can display on template, when i try to populate authenticated.employee.name the console show me an error but data can display.

TypeError:无法读取未定义的属性名称"

TypeError: Cannot read property 'name' of undefined

任何人都可以帮助我吗?

Anyone can help me ?

错误

对不起,我的英语不好. ^ _ ^

Sorry my english is bad. ^_^

推荐答案

显示数据时,请尝试如下操作:

When you display your data try like this:

authenticated.employee && authenticated.employee.name

authenticated.employee ? authenticated.employee.name : ''

这是因为暂时未定义authenticated.employee.

该错误将消失.

您可以在此了解更多.

这篇关于呈现错误:"TypeError:无法读取未定义的属性'名称'" (Vue)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆