I would like to make an object list. Each element (of the list) is visualised by a child component. My goal is to create a dynamical list, where I can edit the elements.
I have a parent component <contacts-list-form>
what has an array of contacts an show me them dynamically in <contact-element-form>
:
<contact-element-form v-for="contact in contacts" :key="contact.id" :contact="contact"></contact-element-form>
contact-element-form looks like this:
<template lang="html">
<md-card>
<md-card-header>
<div class="md-title">Contact</div>
<md-icon @click="removeMyself">remove</md-icon>
</md-card-header>
<md-card-content>
<md-input-container>
<md-icon>person</md-icon>
<label>contactName</label>
<md-input name="contactName" v-model="contact.name" required />
</md-input-container>
<md-input-container>
<md-icon>email</md-icon>
<label>contactEmail</label>
<md-input name="contactEmail" v-model="contact.email" required />
</md-input-container>
<md-input-container>
<md-icon>phone</md-icon>
<label>contactPhoneNumber</label>
<md-input name="contactPhoneNumber" v-model="contact.phoneNumber" required />
</md-input-container>
</md-card-content>
</md-card>
</template>
<script>
export default {
props: ["contact"],
data() {
return {
contact: {},
}
},
methods: {
removeMyself() {
console.debug(this.contact.id + ". id will be removed.");
// it will emits to its parent.
}
},
create() {}
}
</script>
<style lang="css">
</style>
How can I reach that data of every <contact-element-form>
is editable, and the parent (<contacts-list-form>
) is noticed about that, and sends the modification to the server.
Thanks for the answers, and advises in advance!