0

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!

1 Answer 1

3

Have you tried this:

  mounted() {
    var self = this;
    this.flatpicker = flatpickr(self.$refs.dateInput, {
      onChange(date) {
        self.$emit("dateChanged", date);
      }
    });
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.