简体   繁体   English

从方法对象数组返回值

[英]Return values from an array of method objects

I'm building a date range picker in Vue.js and I have created an array of methods of preset ranges 我正在Vue.js中构建日期范围选择器,并且创建了一系列预设范围的方法

presetRanges:{
  last7Days(){
    return{
      label: 'Last 7 days',
      dateRange:{
        start: this.$moment(today).substract(7, 'd')
      }
    }
  },
  last30Days(){
    return{
      label: 'Last 30 days',
      dateRange:{
        start: this.$moment(today).substract(30, 'd')
      }
    }
  },
  last60Days(){
    return{
      label: 'Last 60 days',
      dateRange:{
        start: this.$moment(today).substract(60, 'd')
      }
    }
  },
}

In a for loop, I want to display each method's returned label. 在for循环中,我想显示每个方法的返回标签。 The following code is what I used to do, but apparently it doesn't work anymore? 以下代码是我曾经做过的,但是显然不再起作用了吗?

<li v-for="(item, idx) in presetRanges" :key="idx">"
  {{ item.label }} 
</li>

I have also tried {{ item().label }} and it doesn't work either. 我也尝试过{{ item().label }} ,但它也不起作用。

<li v-for="range in presetRanges">
  {{ range.label }} 
</li>

This should work in your case 这应该在您的情况下有效

您可能弄错了对象的结构,应在对象中将函数写为a: () => () ,因此问题的解决方案将在https://codepen.io/mohithg/笔/ VGEjrV?编辑= 1011

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM