猿问

el-table中如何使用computed属性

例如table中有个deptType,返回的值是0,1,2,3 等。要根据0,1,2,3替换成对应的文字。如何操作?


<el-table ref="multipleTable" :data="tabledData" border style="width:100%"  

     :row-class-name="tableRowClassName"  @selection-change="handleSelectionChange" 

    @row-dblclick="dbclick" @select="selectRow" class="tableClass"

    :header-cell-style="headerRowClass">

    <el-table-column type="selection" width="55"></el-table-column>

    <el-table-column prop="deptId" label="机构编码"></el-table-column>

    <el-table-column prop="deptName" label="机构名称"></el-table-column>

    <el-table-column prop="deptType" label="机构类型"></el-table-column>

    <el-table-column prop="orderNum" label="排序"></el-table-column>

    <el-table-column prop="leader" label="负责人"></el-table-column>

    <el-table-column prop="phone" label="联系电话"></el-table-column>

    <el-table-column prop="email" label="邮箱"></el-table-column>

    <el-table-column prop="deptLogo" label="Logo"></el-table-column>

    <el-table-column prop="remark" label="备注"></el-table-column>

</el-table>


holdtom
浏览 2522回答 1
1回答

皈依舞

使用Scoped slot//mfunc是你的转换函数,或者使用filter<el-table-column prop="deptType" label="机构类型">&nbsp; &nbsp; <template slot-scope="scope">&nbsp; &nbsp; &nbsp; &nbsp; <span>{{ mfunc(scope.row.deptType) }}</span>&nbsp; &nbsp; </template></el-table-column>methods: {&nbsp; &nbsp; mfunc(num){&nbsp; &nbsp; &nbsp; &nbsp; let result = num&nbsp; &nbsp; &nbsp; &nbsp; switch(num){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 0: result = 'a';break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return result&nbsp; &nbsp; }}
随时随地看视频慕课网APP
我要回答