天天看点

解决el-table某列数据无法修改内容问题

因后台返回值不符合要求,列数据时间值的末尾都带有.0,要求去掉。现按以下即可解决。

解决前:

解决el-table某列数据无法修改内容问题

一开始是想用过滤方法scope.row.newCommitTime | filters解决,但没法改变内容所以行不通。

<el-table-column prop="newCommitTime" label="最新时间" sortable width="144px" align="center">
    <template slot-scope="scope">{{scope.row.newCommitTime=='null'?'':scope.row.newCommitTime|filters}}</template>
</el-table-column>
           

经研究最终使用el-table-columm的属性:formatter就能修改为想要的内容。

<el-table>
	<el-table-columm prop="newCommitTime" label="最新时间" sortable :formatter="formatTime" width="144px" align="center"></el-table-columm>
</el-table>

formatTime(row,column){//解决最新时间和消费时间列值末尾多出.0问题
   if(row[column.property] === 'null'){//有字符串'null'则为空
       row[column.property] = ''
   }
   if(row[column.property] !== null){//不为null则进行范围截取
       let val = row[column.property].substr(0,19)//从e开始取19个数
       return val
   }
},
           

解决后:

解决el-table某列数据无法修改内容问题

继续阅读