Context
I'm using Vue2.jsto implement pickerOptions to preselect dateRange. I created a function createDate that does what it sounds. The DatePicker component comes from here
Issue
I don't know the right way to call the function createdDate within the object pickerOptions and within the callback function onClick(picker)
When I do so I got this error Uncaught TypeError: this.createdDate is not a function. This makes sense since this reffers to
Object {__ob__: Observer}
onClick:function onClick(picker)
text:"Last week"
What should I do to be able to access my function createDate or how to call it ?
export default {
name: 'app',
data() {
return {
private: {
pickerOptions: {
shortcuts: [{
text: 'Last week',
onClick(picker) {
const end = new Date();
const start = this.createDate(-7);
picker.$emit('pick', [start, end]);
}
}]
}
}
}
},
methods: {
createDate(days, months, years) {
let date = new Date();
date.setDate(date.getDate() + days);
date.setMonth(date.getMonth() + months);
date.setFullYear(date.getFullYear() + years);
return date;
},
}
};