[Vuejs]-Vuejs how to use method in include component

0👍

In your child component add-user-form you can use a custom event when user submits or edits a field.

I’m not sure how your child component looks like but you can do something like this:

child component

<label>
  Username:
  <input
    v-on:input="$emit('usernameChanged', $event.target.value)"
  >
</label>

parent component

<div v-if="operation.operationName=='addUser'">
  <add-user-form
    :module="module"
    :operation="operation"
    v-on:usernameChanged="validateUsername"
  >
  </add-user-form>
</div>

and add a method validateUsername

methods:{
  validateUsername(value){
    //validate username
  }
}

Leave a comment