VUE -- 對 Element UI table中數據進行二次處理


時間——日期

后台經常給我們返回的是 時間戳 (例如:1535620671)

這時候我們頁面展現的時候需要將時間戳轉換為我們要的格式 例如 (YYYY-MM-DD HH:mm:ss)

如果是在Element UI table中 我們需要用到 formatter 屬性

formatter 用來格式化內容

<code>Function(row, column, cellValue, index)</code>

 

使用方法:

<el-table-column prop="Start" :formatter="dateFormat"  label="開始時間"></el-table-column>

 

methods

 //時間格式化
                dateFormat:function(row, column) {
                    var date = row[column.property];
                    if (date == undefined) {
                        return "";
                    }
                    return moment(date).format("YYYY-MM-DD HH:mm:ss");
                },

 

0—1 是—否 成功—失敗

**

將后台返回給我們的0或者1 轉換成我們需要的狀態 例如 是否 成功失敗 或者顏色狀態

使用方法

<el-table-column prop="IsConst" :formatter="formatRole" label="是否是常量"></el-table-column>

 

methods

 formatRole: function(row, column) {
                return row.IsConst == true ?  "是": "否"
            },

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM