vue根据数字显示对应的文字状态

我的方法

原来的样式

想要显示的样式

 

方式一:使用slot-scope+计算属性;(关于计算属性传参,参考的是https://blog.csdn.net/weixin_40841731/article/details/83374872

方式二:使用slot-scope

<template>
   <el-table :data="TemplateList" highlight-current-row>
      <el-table-column  label="模板类型方式一">
          <template slot-scope="scope">
                {{computedSiteType(scope.row.SiteType)}}
          </template>
      </el-table-column>
      <el-table-column  label="模板类型方式二">
          <template slot-scope="scope">
                 {{options[scope.row.SiteType]['label']}}
          </template>
      </el-table-column>
   </el-table>
<template>

computed:{
    computedSiteType(){
        return function(siteType){
            return this.options[siteType]['label']
        }
    },
},

data(){
  options: [
    {
        value: "0",
        label: "全部"
    },
    {
        value: "1",
        label: "PC版"
    },
    {
        value: "2",
        label: "手机版"
    }...
  ],
}

 

 

别人的方法

使用map定义

// 定义字典

const map = {boolean: ['否', '是']}
// 或者

const map = {boolean: {0: '否', 1: '是', 2: '不知道'}}
// 调用

<div>{{map.boolean[item.enable]}}</div>

 

或者使用计算熟属性

<div id="app"><h1>{{ isture }}</h1></div>
<script>
var app = new Vue({
  el : "#app",
  data : {
    info:[{"id":"123","code":"Y002","name":"芝士饼干","channel":"网银","description":"网银","enable":1,"order":2}]
  },
  computed : {
    isture : function(){
      return this.info[0]['enable']==1 ? "是":"否"
    }
  }
})
</script>

https://segmentfault.com/q/1010000011161776

 

  • 11
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值