[Vuejs]-Unique id for each instance of component

2👍

you can use ref property:

<form ref="form">
...
</form>

jQuery code:

$(this.$refs.form).serialize();

but, why not to use v-model to get the values in Vue?

👤jacky

2👍

In Vue document

While explicitly defined props are preferred for passing information
to a child component, authors of component libraries can’t always
foresee the contexts in which their components might be used. That’s
why components can accept arbitrary attributes, which are added to the
component’s root element.

You don’t need to declare id attribute in Form.vue component

But if you want to use id as a property and refer to is as this.id, you should declare id as a props

Form.vue

<form :id="id"> <!--  don't pass id here -->
</form>

<script>
export default {
  props: ['id'] // we need to declare id here
}
</script>

and when submit form

submitForm(activity) {
  let $form = $("#" + this.id);
}

and in Main.vue

<Form id="form1"></Form>
<Form id="form2"></Form>
👤ittus

Leave a comment