前端使用vue+element-ui,我们经常会使用table来展示从后台请求回来的数据,但是,如果被请求回来数据是Boolean类型的时候,在table的列上,就不能像普通的字符串数据一样,被展示出来,这个时候,我们需要做的就是对布尔值数据进行格式的转化。

例如:

<el-table :data="rows" ref="datagrid" border="true" highlight-current-row="true" style="width: 100%">
              
                <el-table-column prop="tableId" label="表id" :show-overflow-tooltip="true">                    </el-table-column>
             
                <el-table-column prop="pk" label="是否为主键" :formatter="formatBoolean"
                                 :show-overflow-tooltip="true"></el-table-column>
              
    
 </el-table>

列“是否为主键”的后台返回值为布尔值‘true’或‘false’,我们要想让其在页面上展示,就用:formatter="formatBoolean"属性,对该值进行格式转换,JS代码如下:

 /*布尔值格式化:cellValue为后台返回的值
*/
            formatBoolean: function (row, column, cellValue) {
                var ret = ''  //你想在页面展示的值
                if (cellValue) {
                    ret = "是"  //根据自己的需求设定
                } else {
                    ret = "否"
                }
                return ret;
            },

好了,这样的话就可以看到了,日期类型的数据展示与这个同理!

GitHub 加速计划 / eleme / element
15
3
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:4 个月前 )
c345bb45 1 年前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 1 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐