呈现错误:"TypeError:无法读取未定义的属性'名称'" (Vue) [英] Error in render: "TypeError: Cannot read property 'name' of undefined" (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屋!