| | |
| | | Esercizio |
| | | </header> |
| | | <active-user :username="user.username" :age="user.age"></active-user> |
| | | <user-data></user-data> |
| | | <user-data @update-user="updateUser"></user-data> |
| | | </section> |
| | | </template> |
| | | |
| | |
| | | age: "38", |
| | | } |
| | | } |
| | | }, |
| | | methods:{ |
| | | updateUser(user, age){ |
| | | this.user.username = user; |
| | | this.user.age = age; |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | |
| | | props: { |
| | | username: { |
| | | title: String, |
| | | required: true |
| | | required: true, |
| | | }, |
| | | age: { |
| | | title: String, |
| | | required: true |
| | | required: true, |
| | | }, |
| | | } |
| | | } |
| | |
| | | <template> |
| | | <form @submit.prevent="submitData"> |
| | | <div> |
| | | <label>Utente: </label> |
| | | <input type="text"> |
| | | <input type="text" v-model="username"> |
| | | </div> |
| | | <div> |
| | | <label>Eta: </label> |
| | | <input type="text"> |
| | | <input type="text" v-model="age"> |
| | | </div> |
| | | <div> |
| | | <button>Update</button> |
| | | </div> |
| | | </form> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | data(){ |
| | | return { |
| | | username: "", |
| | | age: "", |
| | | } |
| | | }, |
| | | emits: ['update-user'], |
| | | methods:{ |
| | | submitData() { |
| | | |
| | | if(this.username !== "" && this.age !== ""){ |
| | | |
| | | this.$emit('update-user', this.username, this.age); |
| | | } else { |
| | | alert("insert data") |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | </script> |