鍍金池/ 問答/Linux  HTML/ vue中如何實(shí)現(xiàn)三種狀態(tài)的數(shù)據(jù)判斷?

vue中如何實(shí)現(xiàn)三種狀態(tài)的數(shù)據(jù)判斷?

我從后臺(tái)拿到一段數(shù)據(jù),是一段數(shù)組對(duì)象,格式如下:

[{name: 'a', state: 0}, {name: 'b', state: 1}, {name: 'c', state: 2}]

我需要在循環(huán)中判斷它的state來給定不同的文字提示
例如:
0------就是辦理中
1------就是已結(jié)辦
2------就是已中止
我的代碼如下:

<template>
  <div
  v-for="(item, index) in formatInfo"
  :key="index"
  class="result-progressBox">
    <div class="result-progress">
      <div class="result-progresstName">{{item.state}}</div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      info: this.$store.state.IndexStore.Progress.cardSchedule //假設(shè)這里得到的格式就會(huì)上面的數(shù)組對(duì)象格式
    }
  }
  computed: {
    formatInfo () {
      this.info.map((current, index) => {
        switch (current.state) {
          case '0': current.state = '辦理中'
            break
          case '1': current.state = '已辦結(jié)'
            break
          case '2': current.state = '已中止'
            break
        }
      })
    }
  },
}
</script>

我這么寫得不到我想要的效果,看不到‘辦理中’等狀態(tài) 只能渲染出來1 或者 0 或者 2### 問題描述

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

回答
編輯回答
爆扎

三元運(yùn)算嵌套一下就可以了啊,干嘛要computed
{{(item.state==0?'辦理中':(item.state==1?:'已結(jié)辦':'已中止'))}}

2018年1月1日 07:11
編輯回答
掛念你

哈哈剛做的項(xiàng)目中就是你說的 我的是未認(rèn)證 已認(rèn)證 認(rèn)證中
圖片描述

2017年5月11日 04:19
編輯回答
挽青絲
{{['辦理中', '已辦結(jié)', '已中止'][item.state]}}

這樣不就行了嗎

2017年9月22日 13:34