vue :formatter 對列的值進行處理
阿新 • • 發佈:2019-01-24
需要對型別進行處理
<el-table size="small" :data="TableData.lists" :header-cell-style="headerStyle" border highlight-current-row style="width: 100%">
<el-table-column :align="TableData.align" prop="offer_id" label="套餐ID" min-width="200"></el-table-column>
<el-table-column :align="TableData.align" prop="offer_name" label="套餐名稱" min-width="250"></el-table-column>
<el-table-column :align="TableData.align" prop="price" label="套餐價格" min-width="140"></el-table-column>
<el-table-column :align="TableData.align" prop="effect_type" label="型別" :formatter="typeFormatter" min-width="180"></el-table-column>
</el-table>
兩種方式
- if…else…
typeFormatter: function(row, column) {
return row.effect_type == 0
? "當天有效"
: row.effect_type == 1
? "當月有效"
: row.effect_type == 2
? "季度有效"
: row.effect_type == 3
? "半年有效"
: row.effect_type == 4
? "1年有效"
: row.effect_type == 5
? "本週有效"
: row.effect_type == 6 ? "連續包月" : "無限制";
}
- switch…case…
typeFormatter: function(row, column) {
switch (row.effect_type) {
case "0":
return "當天有效";
break;
case "1":
return "當月有效";
break;
case "2":
return "季度有效";
break;
case "3":
return "半年有效";
break;
case "4":
return "1年有效";
break;
case "5":
return "本週有效";
break;
case "6":
return "連續包月";
break;
case "9":
return "已啟用";
break;
}
}