I've created a vue directive that I'm attaching to multiple input elements on the same page, and have noticed that when I start typing in one of them, the 'update' event fires for all elements in the page. I had expected to only have one event, for the particular element that I had updated.
My question is, Is there a way to prevent the event firing, or filtering the events so that I can handle only the input that is changing?
Heres the code for my directive and view:
Vue.directive('test', {
bind: (el) => {
console.log(el.id + " bound")
},
update: (el) => {
console.log(el.id + " updated")
}
})
new Vue({
el: "#app",
data: {
testval1: null,
testval2: null,
},
methods: {
}
})
and the template:
<div id="app">
<input id="testinput1" v-model="testval1" v-test />
<input id="testinput2" v-model="testval2" v-test />
</div>
Here is a JSFiddle of the issue: https://jsfiddle.net/eywraw8t/415288/
In this JSFiddle, you can see in the console that if you type into the input field, it fires the update for both input fields.