recupero il codice della precedente lezione e lo spezzo in componenti
2 files added
1 files modified
New file |
| | |
| | | <template> |
| | | <section> |
| | | <h2>My friends</h2> |
| | | <ul> |
| | | <friend-contact></friend-contact> |
| | | <friend-contact></friend-contact> |
| | | </ul> |
| | | </section> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | data() { |
| | | return { |
| | | friends: [ |
| | | { |
| | | id: "manuel", |
| | | name: "Manuel Lorenz", |
| | | phone: "01234 5678 991", |
| | | email: "manuel@localhost.com", |
| | | }, |
| | | { |
| | | id: "julie", |
| | | name: "Julie Jones", |
| | | phone: "09876 543 221", |
| | | email: "julie@localhost.com", |
| | | }, |
| | | ], |
| | | } |
| | | }, |
| | | }; |
| | | </script> |
New file |
| | |
| | | <template> |
| | | <li> |
| | | <h2>{{ friend.name }}</h2> |
| | | <button @click="toggleDetails"> |
| | | {{ detailsAreVisible ? 'Hide' : 'Show' }} Details |
| | | </button> |
| | | <ul v-if="detailsAreVisible"> |
| | | <li><strong>Phone:</strong> {{ friend.phone }}</li> |
| | | <li><strong>Email:</strong> {{ friend.email }}</li> |
| | | </ul> |
| | | </li> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | data() { |
| | | return { |
| | | detailsAreVisible: false, |
| | | friend: { |
| | | id: "manuel", |
| | | name: "Manuel Lorenz", |
| | | phone: "01234 5678 991", |
| | | email: "manuel@localhost.com", |
| | | } |
| | | } |
| | | }, |
| | | methods: { |
| | | toggleDetails() { |
| | | this.detailsAreVisible = !this.detailsAreVisible; |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | |
| | | import { createApp } from 'vue'; |
| | | import { createApp } from "vue"; |
| | | |
| | | createApp({}).mount(''); |
| | | import App from "./App.vue"; |
| | | import FriendContact from "./components/FriendContact.vue"; |
| | | |
| | | const app = createApp(App); |
| | | |
| | | app.component("friend-contact", FriendContact); |
| | | |
| | | app.mount("#app"); |