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

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

{{totalWords[index]}}
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; }, }

方法二:

{{totalWords[item.orderStatus]}}
data() { return { totalWords: { 'unReceipt':'合计', 'unConsignment':'合计', 'unComment':'合计', 'unPay':'应付' }, }; }, computed: { ...mapState(['allOrders']), },

你可能感兴趣的:(mpvue v-for 根据变量改变值(代替filter))