【需求】在element中,將表格中的數據進行處理,而後渲染出來。例如,將數據保留小數點後兩位顯示。函數
【知識點】formatter:用來格式化內容spa
【分析】在element 的table中,實現的過程是,數據須要綁定在 :data="tableData" 中,而後經過prop讀取tableData中的key,這樣一列的數據便可顯示出來。如今須要對返回的數據進行格式化,能夠用formatter屬性,例如在「手續費」中,須要對數據進行保留兩位小數,經過調用handelFix函數。code
注:這裏在handelFix函數中,要經過傳入property得到當前那一列的prop值,否則獲取不到值。orm
templaterouter
<el-table :data="tableData" stripe empty-text v-loading="listLoading" element-loading-text="拼命加載中" style="width: 100%"> <el-table-column :formatter="handelFix" prop="fuwufei" label="手續費"> </el-table-column> <el-table-column prop="zhuangtai" label="狀態" width="160"> </el-table-column> <el-table-column prop="zizhuangtai" label="子狀態" width="160"> </el-table-column> <el-table-column prop="shenheren" label="審覈人"> </el-table-column> <el-table-column label="備註"> <template scope="custom"> <el-button type="text" @click="open(custom.row.userId)">詳情</el-button> </template> </el-table-column> <el-table-column prop="" fixed="right" width='150' label="操做"> <template scope="scope"> <router-link :to="{ path: 'actionRecord', query: { gnhid: '5905d474b74e756d40b6a7a7' }}"><el-button type="warning" size='mini'>操做記錄</el-button></router-link> <router-link :to="{ path: 'newPage', query: { userId: scope.row.userId,gnhId:''}}" v-show="!zhijianIsShow"><el-button type="success" size='mini' >新頁面</el-button></router-link> <router-link :to="{ path: 'newPageZhijian', query: { userId:'',gnhId: scope.row.id }}" v-show="zhijianIsShow"><el-button type="success" size='mini' @click="">質檢頁面</el-button></router-link> </template> </el-table-column> </el-table>
scriptblog
handelFix(row, column){ return row[column.property].toFixed(2) },