I have this line in my vue.js application
<input type="text" v-on:input="cssClass=$event.target.value">
I know that in javascript I can get event.target.value. I think that the above code is Vue.js specific code, but I'm not sure. Need confirmation.
I have this line in my vue.js application
<input type="text" v-on:input="cssClass=$event.target.value">
I know that in javascript I can get event.target.value. I think that the above code is Vue.js specific code, but I'm not sure. Need confirmation.
Share Improve this question edited Jan 15, 2017 at 21:42 Sage 4,9371 gold badge23 silver badges29 bronze badges asked Jan 10, 2017 at 23:15 Simon SuhSimon Suh 10.9k28 gold badges90 silver badges119 bronze badges 3-
you are using a custom attribute
v-on:input...
so it's not default to javascript – Ibu Commented Jan 10, 2017 at 23:17 - if I take out the dollar sign, the vue.js application doesn't work. So this is a vue.js code right? :) – Simon Suh Commented Jan 10, 2017 at 23:17
- sorry, I forgot to specify. I was wondering specifically about the '$event' part. – Simon Suh Commented Jan 10, 2017 at 23:18
2 Answers
Reset to default 6v-on:input
will consume the actual DOM event of the input
initially, store against $event
, a special variable, and then make it available to the function being called. In this case you access $event.target.value
to get the newly input value from the event. Methods in Inline Handlers
Hope that helps.
You can use $event because of VueJS. Angular2 also has the same special variable. What exactly $event object do in Angular 2?