I'm using vuejs-datepicker component in a project however I need some custom behaviour that's why I decided to create my own datepicker and inject vuejs-datepicker as a mixin. The solution works fine but I'm looking for a way to call the parent method inside my overridden one. That's how my component looks for now:
import Datepicker from 'vuejs-datepicker'
export default {
props: {
/**
* My custom property startDate to open a calendar on the given date by default
*/
startDate: {
validator: function (val) {
return val === null || val instanceof Date || typeof val === 'string'
},
default: new Date()
}
},
mixins: [ Datepicker ],
methods: {
/**
* I override parent method setPageDate to read default startDate when none is specified
*/
setPageDate (date) {
// my code to set default date from the property
if (!date) {
date = this.startDate
}
// this part is the same as in the original method
this.pageDate = new Date(date.getFullYear(), date.getMonth(), 1, date.getHours(), date.getMinutes()).getTime()
}
}
}
Just one line of copied code isn't a big deal but I expect I need to override more methods in the future. So I'm looking for the best way to call that parent method inside my implementation, something like this.parent(date)
or this.super(date)
. Is it possible at all?
There is no super
or anything like that. You could do something like this:
setPageDate (date) {
// my code to set default date from the property
if (!date) {
date = this.startDate
}
Datepicker.methods.setPageDate.call(this, date)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With