Cristiano Magro
2024-12-28 8480d4ef05d995ee67c1460cf273c899fa59e89c
commit | author | age
f31b9e 1 <template>
CM 2     <li>
8480d4 3         <h2>{{ name }} {{ isFavorite ? '(Favorite)' : '' }}</h2>
f31b9e 4         <button @click="toggleDetails">
CM 5             {{ detailsAreVisible ? 'Hide' : 'Show' }} Details
7b062d 6         </button>
CM 7
8         <button @click="toggleFavorite">
9             Toggle favorite
f31b9e 10         </button>
CM 11         <ul v-if="detailsAreVisible">
498b47 12             <li><strong>Phone:</strong> {{ phoneNumber }}</li>
CM 13             <li><strong>Email:</strong> {{ emailAddress }}</li>
f31b9e 14         </ul>
CM 15     </li>
16 </template>
17
18 <script>
19 export default {
fb09dc 20     // props: [
CM 21     //     'name',
22     //     'phoneNumber',
23     //     'emailAddress',
24     //     'isFavorite'
25     // ],
26     props: {
8480d4 27         id:{
CM 28             title: String,
29             required: true
30         },
fb09dc 31         name: {
CM 32             title: String,
33             required: true
34         },
35         phoneNumber: {
36             title: String,
37             required: true
38         },
39         emailAddress: {
40             title: String,
41             required: true
42         },
43         isFavorite: {
c4371d 44             title: Boolean,
fb09dc 45             required: false,
c4371d 46             default: false,
CM 47             // validator: function (value) {
48             //     return value === '1' || value === '0';
49             // }
fb09dc 50         },
CM 51     },
52
f31b9e 53     data() {
CM 54         return {
55             detailsAreVisible: false,
56         }
57     },
58     methods: {
59         toggleDetails() {
60             this.detailsAreVisible = !this.detailsAreVisible;
61         },
7b062d 62         toggleFavorite() {
8480d4 63             // this.friendIsFavorite = !this.friendIsFavorite;
CM 64             this.$emit('toggle-favorite', this.id);
7b062d 65         },
f31b9e 66     },
CM 67 };
68 </script>