天天看點

解決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某列資料無法修改内容問題

繼續閱讀