美文网首页
mpvue v-for 根据变量改变值(代替filter)

mpvue v-for 根据变量改变值(代替filter)

作者: 斐硕人 | 来源:发表于2019-05-13 12:25 被阅读0次

    根据orderStatus改变span内的值
    方法一:

    <div v-for="(item,index) in allOrders" :key="index" class="orders-board">
    <span>{{totalWords[index]}}</span>
    <div>
    
    
      data() {
        return {
          totalWords: []
        };
      },
      computed: {
        ...mapState(['allOrders']),
      },
      mounted() {
        this.createTotalWords();
      },
      methods: {
        createTotalWords() {
          const totalWords = this.allOrders.map(order => {
            if (order.orderStatus === 'unPay') {
              return '应付:';
            }
            return '合计:';
          });
          this.totalWords = totalWords;
        },
      }
    

    方法二:

    <div v-for="(item,index) in allOrders" :key="index" class="orders-board">
    <span>{{totalWords[item.orderStatus]}}</span>
    <div>
    
    
      data() {
        return {
          totalWords: {
            'unReceipt':'合计',
            'unConsignment':'合计',
            'unComment':'合计',
            'unPay':'应付'
          },
        };
      },
      computed: {
        ...mapState(['allOrders']),
      },
    
    

    相关文章

      网友评论

          本文标题:mpvue v-for 根据变量改变值(代替filter)

          本文链接:https://www.haomeiwen.com/subject/gqslaqtx.html