Reputation: 191
I have form like this
<form v-on:submit.prevent="save_data(this)"></form>
and function like this
methods: {
save_data: function(f){
}
}
on jquery we can get form like this
$(f)[0]
my question is, how to get that form using vue js? thanks for your answer
Upvotes: 2
Views: 93
Reputation: 289
You can use $event
equavalent to javascript event
..
<form v-on:submit.prevent="save_data($event)"></form>
methods: {
save_data: function(f){
console.log(f.target); // form element
}
}
Upvotes: 3
Reputation: 953
To get the actual form element you can assing it a ref attribute on the HTML like so:
<form v-on:submit.prevent="save_data(this)" ref="myForm"></form>
Then in your root instance of Vue you can retrieve the element like so:
this.$refs.myForm.$el
Upvotes: 2