Vue component over-complication I'm building a date range selector, and while this works, I feel like I'm making it more complicated than it needs to be. Is there a more elegant way of writing this?

Possibly using computed values or watches?

&lt;template&gt;
&lt;form&gt;
    &lt;select  @change="rangeSelection"&gt;           
            &lt;option 
                v-for="(option, key) in rangeOptions"
                :key="key"
                :value="key"&gt;
                {{option.display}}
            &lt;/option&gt;
    &lt;/select&gt;
    &lt;/form&gt;
&lt;/template&gt;

&lt;script&gt;
import moment from 'moment';

export default {
  name: 'DateRangeChooser',
  data: () =&gt; {
    return {
        selectedRange: "last7Days",
        startDate: moment().subtract(8, 'days'),
        endDate: moment().subtract(1, 'days'),
        rangeOptions: {
            last7Days: {
                display: 'Last 7 Days',
                startDate: moment().subtract(8, 'days'),
                endDate: moment().subtract(1, 'days')
            },
            lastWeek: {
                display: 'Last Week',
                startDate: moment().startOf('week').subtract(1, 'week'),
                endDate: moment().endOf('week').subtract(1, 'week')
            },
            last30days: {
                display: 'Last 30 days',
                startDate: moment().subtract(31, 'days'),
                endDate: moment().subtract(1, 'days')
            }
        }
    }
  },  
  methods: {
    rangeSelection: function(e){
        this.endDate = this.rangeOptions[e.currentTarget.value].endDate;
        this.startDate = this.rangeOptions[e.currentTarget.value].startDate;
    }
  }
};
&lt;/script&gt;
Yes you can use computed properties:

computed: {
    endDate: function() {
      //determine endDate based on value of selectedRange
    },
    startDate: function() {
      //determine startDate based on value of selectedRange
    }
}


And v-model can be used to bind the value of the select list to that data property:

&lt;select v-model="selectedRange"&gt;


Then use that property in the computed properties:

  computed: {
    endDate: function() {
      return this.rangeOptions[this.selectedRange].endDate;
    },
    startDate: function() {
      return this.rangeOptions[this.selectedRange].startDate;
    }
  }


With this approach there is no need to define the rangeSelection method and bind it to the onchange property.

rangeOptions could also be moved outside the component, and then the first key could be used to select the default value of selectedRange instead of hard coding it. See the snippet below. 



const rangeOptions = {
  last7Days: {
    display: 'Last 7 Days',
    startDate: moment().subtract(8, 'days'),
    endDate: moment().subtract(1, 'days')
  },
  lastWeek: {
    display: 'Last Week',
    startDate: moment().startOf('week').subtract(1, 'week'),
    endDate: moment().endOf('week').subtract(1, 'week')
  },
  last30days: {
    display: 'Last 30 days',
    startDate: moment().subtract(31, 'days'),
    endDate: moment().subtract(1, 'days')
  }
};
const form = new Vue({
  el: '#DateRangeChooser',
  data: () =&gt; {
    return {
      selectedRange: Object.keys(rangeOptions)[0],
      rangeOptions
    }
  },
  computed: {
    endDate: function() {
      return rangeOptions[this.selectedRange].endDate;
    },
    startDate: function() {
      return rangeOptions[this.selectedRange].startDate;
    }
  }
});
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"&gt;&lt;/script&gt;
&lt;script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"&gt;&lt;/script&gt;

&lt;div id="DateRangeChooser"&gt;
  &lt;select v-model="selectedRange"&gt;
    &lt;option v-for="(option, key) in rangeOptions" :key="key" :value="key"&gt;
      {{option.display}}
    &lt;/option&gt;
  &lt;/select&gt;
  &lt;div&gt;Start: {{startDate.format('LL')}}&lt;/div&gt;
  &lt;div&gt;End: {{endDate.format('LL')}}&lt;/div&gt;
&lt;/div&gt;




Edit

@blindman67 brought up an interesting point: 


  Sorry my VUE knowledge is limited but I thought computed properties were cached. Could be a problem in some edge cases, eg time near midnight and user selects, then changes their mind waits till after midnight selects again?1


That is true:


  ... computed properties are cached based on their dependencies2


if caching is an issue, then you may need to look at using a watcher or just calculate the computed property each time instead of referencing values within this.rangeOptions.

1Vue component over-complication

2https://vuejs.org/v2/guide/computed.html#Computed-Caching-vs-Methods