9

I have an event in vuejs

methods: {
   filterPeople: function filterPeople() {
      $(event.target).closest('li').addClass('active');
});

In firefox I get an error

TypeError: event is undefined
mounted/<
re/e.prototype.$emit
filterPeople

Any idea why this does not work in FF

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192

3 Answers3

5

Firefox doesn't have a global event object.

WebKit follows IE's old behavior of using a global symbol for "event", but Firefox doesn't.

Simply add it as a parameter.

methods: {
  filterPeople: function filterPeople(event) {
    $(event.target).closest('li').addClass('active');
  }
}
Bert
  • 80,741
  • 17
  • 199
  • 164
1

You must pass the event as parameter, should be :

methods: {
  filterPeople: function(event) {
    $(event.target).closest('li').addClass('active');
  }
}

NOTE : The name was duplicated in the function definition.

Hope this helps.

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
0

Pass event to function filterPeople(). Like this:

methods: {
  filterPeople: function filterPeople (e) {
  $(e.target).closest('li').addClass('active');
});