Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘0‘)

报错:Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘0’)

insert image description here

Problem code:

<el-table-column prop="number" label="总用例数 / 失败用例数" align="center" width="200">
   <template #default="scope">
      <span>{
    
    {
    
    scope.row.number[0]}}</span>
      <span style="margin:0 3px">/</span>
      <span class="failNumStyle" @click="toDetail(scope.row.id)">{
    
    {
    
    scope.row.number[1]}}</span>
   </template>
</el-table-column>

insert image description here

reason:

Asynchronously display the initial data displayed first, and there is no data at this time

Correct code:

<el-table-column prop="number" label="总用例数 / 失败用例数" align="center" width="200">
  <template #default="scope">
     <span v-if="scope.row.number">{
    
    {
    
    scope.row.number[0]}}</span>
     <span style="margin:0 3px">/</span>
     <span class="failNumStyle" @click="toDetail(scope.row.id)" v-if="scope.row.number"
        {
    
    {
    
    scope.row.number[1]}}
     </span>
  </template>
</el-table-column>

Guess you like

Origin blog.csdn.net/weixin_42365757/article/details/127426423