Vue-da Melumat Elave Etmek Ucun Komponent
Indi yeni userler elave etmek ucun formani reallasdiraq. Bu formani ayrı bir komponent kimi edecik. Reallasdirmaga baslayaq. Evvelce ana komponentde user elave etmek ucun metod yaradaq:
methods: {
add(name, surn) {
let id = this.users.length + 1;
this.users.push({
id,
name,
surn
});
}
}
Ana komponentin templatinde usaq komponenti elave edek:
<template>
<UserForm @add="add" />
</template>
Usaq komponentde inputlari idare etmek ucun xususiyyetler yaradaq:
data() {
return {
newName: '',
newSurn: '',
}
}
Usaq komponentde melumatlari yadda saxlamag ucun metod yaradaq:
methods: {
save() {
this.$emit('add', this.newName, this.newSurn);
}
}
Usaq komponentin templatini yaradaq:
<template>
<input v-model="newName">
<input v-model="newSurn">
<button @click="save">
save
</button>
</template>
Yeni isci elave etmek ucun formani reallasdirin.