如何利用computed计算出来第一个OrderItems的对象?

// 如何利用computed计算出来第一个OrderItems的对象
this.thumbnail = res.OrderInfo.OrderItems[0].Thumbnail;
this.goodsSource = res.OrderInfo.OrderItems[0].GoodsSource;
this.goodsName = res.OrderInfo.OrderItems[0].GoodsName;
this.count = res.OrderInfo.OrderItems[0].Count;
this.spec = res.OrderInfo.OrderItems[0].Spec;

数据

clipboard.png

阅读 1k
1 个回答
new Vue({
  data:{
    orderItems: null;
  },
  computed:{
    firstOrderItem(){
      return orderItems != null && orderItems.length > 0 ? orderItems[0] : null;
    }
  },
  methods:{
    getData: function(){
      axios.get('url', someParams).then(res->{this.orderItems = res.data.OrderItems})
    }
  }
});
推荐问题