【发布时间】:2017-12-31 17:40:11
【问题描述】:
我不明白为什么我无法访问 user 对象中的数据。
{
"channel_id": 2,
"user": {
"id": 1,
"name": "Clyde Santiago",
"email": "dexterdev02@gmail.com",
"created_at": "2017-07-25 08:10:58",
"updated_at": "2017-07-25 08:10:58"
},
"message": "ssd"
}
访问channel_id、user、message 很好。但是当我访问user 中的数据时,它会显示错误,
“无法读取未定义的属性‘名称’”
这是我的 Vue 组件中的 HTML
<ul class="list-group">
<li class="list-group-item" v-for="conversation in conversations">
<p>
{{conversation.message}}
</p>
<small>{{conversation.user.name}}</small> // error here
</li>
</ul>
【问题讨论】:
-
什么错误,这些数据是异步检索的?
-
您要访问哪些数据? {{conversation.user}} 是一个对象,所以它应该给出 [object Object]。 {{conversation.user.id}} 会给出用户 ID 等
-
"Cannot read property 'name' of undefined" 这就是错误。我正在使用推送器
-
当我访问 {{conversation.user}} 时很好。但是当我访问 {{conversation.user.name}} 时,它显示错误“无法读取未定义的属性'名称'”
-
这并不意味着
name未定义。这意味着user是。
标签: javascript vue.js vue-component