关于vue+element的table表格prop获取数据是数组的问题

在使用vue和element编写前端页面,渲染列表数据时,table表格属性中的prop获取到的数据是一个数组
后端返回的json数据如下:

{
            "id": 1,
            "score": 90,
            "detail": "商品质量好",
            "sid": 1,
            "code": "100100A",
            "name": "北京xxx科技有限公司",
            "result": "优",
            "comments": [
                {
                    "detail": "商品质量好",
                    "score": 90
                },
                {
                    "detail": "好",
                    "score": 77
                }
            ]
        },
        {
            "id": 2,
            "score": 59,
            "detail": "商品质量差",
            "sid": 2,
            "code": "100200B",
            "name": "江西xxx有限公司",
            "result": "中",
            "comments": [
                {
                    "detail": "商品质量差",
                    "score": 59
                }
            ]
        }

前端页面定义如下(非数组属性代码已省略):

<el-table-column
        label="评价详情"
        width="580"
        prop="comments"
        >
         <template slot-scope="scope">
            <span>
              {{comment.detail}}({{comment.score}}分)
              <br/>
            </span>
         </template>
      </el-table-column>

评价详情列中需将一个公司的评价数组循环渲染展示,采用以下两种解决办法:
1.直接循环comments数组

<el-table-column
        label="评价详情"
        width="580"
        prop="comments"
        >
         <template slot-scope="scope">
            <span v-for="(comment,index) in scope.row.comments" :key="index">
              {{comment.detail}}({{comment.score}}分)
              <br/>
            </span>
         </template>
      </el-table-column>

2.使用ele官方的formatter方法来格式化渲染
在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值