前提:vue2 element-ui table表格 前四列渲染接口1 后两列渲染接口2
问题:现在接口1 有数据,点击按钮调接口2,有数据,表格才显示,但是已刷新页面,页面就没数据了。但是接口1有数据
原因:接口2的数据没有取不到,是个underfined,影响了整个表格页面的渲染
<el-table
ref='filterTable'
:data="inputData"
style="width: 100%"
:header-cell-style="{'text-align':'center'}"
@expand-change="expandChange">
<!-- 其他表格列 -->
<el-table-column
prop="address"
:label="$t('code_people.th4')"
align="center"
min-width="10%" >
<template slot-scope="scope">
<!-- 添加判断逻辑 -->
<span class="fontSize" >
{{ (info && info.status && info.status[scope.$index] && info.status[scope.$index].bitrate)? info.status[scope.$index].bitrate + '科目' : '0科目' }}
</span>
</template>
</el-table-column>
<!-- 其他表格列 -->
</el-table>
在模板中,使用了三元表达式进行条件判断:
- 首先检查
info
是否存在。- 接着检查
info.status
是否存在。- 然后检查
info.status[scope.$index]
是否存在。- 最后检查
info.status[scope.$index].bitrate
是否存在。如果上述所有条件都满足,说明
bitrate
有值,显示info.status[scope.$index].bitrate + '科目'
;否则显示0科目
。