vue+element ui后台返回数据为数字,前台转化成对应的中文显示在表格中

关于根据后台数字显示相应的文字,文档中没有详细说明,所以写这篇博客记录一下。

这里主要介绍三种方法,可以自己的需要选择哦

先放个效果图吧(先说明一下0表示是,1代表否)

 方法一:调用methods中的方法

<el-table-column 
    prop="isAccept" 
    label="是否接受" 
    show-overflow-tooltip
    :formatter="formtype">
</el-table-column>

methods:{
    formtype(cellValue){
        if (cellValue == 0){
            return '否';
        }else if (cellValue == 1){
            return '是';
        };
    },
},

方法二:通过v-if判断

<el-table-column prop="isAccept" label="是否接受">	
    <template slot-scope="scope">
        <span v-if="scope.row.isAccept== 0">否</span>
        <span v-if="scope.row.isAccept== 1">是</span>
        <span v-if="scope.row.isAccept== 2">--</span>
    </template>
</el-table-column>

方法三:通过三目运算符判断

<el-table-column prop="isAccept" label="是否接受">
    <template slot-scope="scope">
        {
   
   { scope.row.isAccept == 1 ? "是" : "否" }}
    </template>
</el-table-column>

猜你喜欢

转载自blog.csdn.net/weixin_55992854/article/details/119698963