Component for adding data in Vue

Let's now implement a form for adding new users. We will make this form as a separate component. Let's start implementing it. First, in the parent component, we will make a method for adding a user:

App.vuemethods: {
  add(name, surn) {
    let id = this.users.length + 1;
    
    this.users.push({
      id,
      name,
      surn
    });
  }
}

In the parent component view, we connect the child:

App.vue<template>
  <UserForm @add="add" />
</template>

In the child component we will create properties to control inputs:

components/UserForm.vuedata() {
  return {
    newName: '',
    newSurn: '',
  }
}

In the child component, we will create a method for saving data:

components/UserForm.vuemethods: {
  save() {
    this.$emit('add', this.newName, this.newSurn);
  }
}

Let's create views for the child component:

components/UserForm.vue<template>
  <input v-model="newName">
  <input v-model="newSurn">
  
  <button @click="save">
    save
  </button>
</template>
Задание 1

Implement a form to add a new employee.