数据类型是这样的:
dataList: [
{
id: 1,
status: 1,
staff: {
id: 12,
name: '管理员',
phone: '12345676879'
}
},
{
id: 1,
status: 1,
staff: {
id: 12,
name: '管理员',
phone: '12345676879'
}
}
]
此时我要遍历这个数组,来将里面的数据渲染到页面上:
<tr v-for="item in dataList" :key="item.id">
<td>{{item.id}}</td>
<td>{{item.staff.name}}</td>
</tr>
死活都拿不到staff中的name,一直报错"TypeError: Cannot read property 'name' of null"
有没有大神遇到过这种问题,该怎么解决啊
试试(item.staff || {}).name