For anyone interested, I solved this by doing the following.
in app.js just above the root instance I created a dateRange variable:
var dateRange = {
debug: true,
state: {
startDate: moment().subtract(29, 'days').format('YYYY-MM-DD'),
endDate: moment().format('YYYY-MM-DD')
},
setDatesAction (startDate, endDate) {
this.state.startDate = startDate
this.state.endDate = endDate
}
};
Then passed this to the root vue instance as below:
var app = new Vue({
router,
data: {
dateRange: dateRange
}
});
The start and end dates are now accessible from all components by:
$root.dateRange.state.startDate
$root.dateRange.state.endDate
And to change the date range I do the following:
vm.$root.dateRange.setDatesAction(moment(start).format('YYYY-MM-DD'), moment(end).format('YYYY-MM-DD'))
I can also watch for changes so I know when to make a new api call:
'$root.dateRange.state.startDate': 'changeDateRange',
'$root.dateRange.state.endDate': 'changeDateRange'
So now every page component shares the same date range which is exactly what I wanted to achieve.
More info here: https://vuejs.org/v2/guide/state-management.html