el-table-column中formatter格式化字典


el-table-column中formatter格式化字典

  • vue 中使用 <el-table-column/> 中的 formatter 格式化内容 🔮

    <template>
      <!-- 列表 -->
    	<el-table :data="list">
        <!-- 需要格式化的内容 -->
        <el-table-column prop="type" label="类型" :formatter="typeFormat">
        </el-table-column>
      </el-table>
    </template>
    <script>
      export default{
        data(){
          return{
            // 表格数据
            list:[],
            // 类型
            typeOptions:[]
          }
        },
        created(){
          this.getList();
          // 查询类型字典
    			this.getDicts('risk_amt_type').then((res) => {
    				this.typeOptions = res.data;
    			});
        },
        methods:{
          // 获取表格数据
          getList(){
            // 后台接收表格数据
            this.list=res.data;
          },
          // 格式化表格内容--类型字典翻译
          typeFormat(row) {
            console.log(row);
    				let type = '';
    				this.typeOptions.forEach(item => {
    					if (row.type == item.dictValue) {
    						type = item.dictLabel;
    					}
    				});
    				return type;
    			},
        }
      }
    </script>
    


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM