2

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

2

2 Answers 2

3

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
   }
}
Sign up to request clarification or add additional context in comments.

Comments

2

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

2 Comments

In the example OP gave, jquery will return a dom element, so the equivalent would be this.$refs.myForm.$el
@smac89 Correct. Edited answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.