Reputation: 1047
I have an issue when trying to access component functions from within the config of plugins. For example, I would like to use vue-flatpickr as so:
mounted() {
this.flatpicker = flatpickr(this.$refs.dateInput, {
onChange(date) {
this.$emit("dateChanged", date);
}
});
}
However, I get an error
Uncaught TypeError: this.$emit is not a function
The problem is not only with emit but also with any function defined in the methods section as this points to the instance of the plugin. I realize this might not be an adequate approach, I am open to any suggestions!
Upvotes: 0
Views: 176
Reputation: 690
Have you tried this:
mounted() {
var self = this;
this.flatpicker = flatpickr(self.$refs.dateInput, {
onChange(date) {
self.$emit("dateChanged", date);
}
});
}
Upvotes: 3