[Vuejs]-Change event not firing when using radio button with VueJS

0👍

You have made mistake in data: {}, it should be in data(){...}:

new Vue({
  el: "#app",
  data() {},
  methods: {
    filterChanged() {
      console.log("You changed the filter");
    }
  }
});

Here is the working sandbox for your code:

Code sandbox link

0👍

I found that when there was something else changing the radio button (eg. radio button being set via a prop() or something) rather than a true human click, the change event wasn’t actually fired.

If you set @click() instead of @change() see if that helps it start firing.

Your code does look correct though, so if you can get JS to not fire it, then that’s most ideal.

-3👍

Agree with Aaron, it’s a function you’re calling, so use: filterChanged()
Also, try using v-on:click="filterChanged()"

In theory, that shouldn’t make a difference, but I’ve found that can help sometimes.

Leave a comment