Cristiano Magro
2024-12-30 ac100de8d8e0fc85e34cde9aec6262259b12f96c
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>
1630a9 15         <button @click="$emit('delete', id)">Delete</button>
f31b9e 16     </li>
CM 17 </template>
18
19 <script>
20 export default {
fb09dc 21     // props: [
CM 22     //     'name',
23     //     'phoneNumber',
24     //     'emailAddress',
25     //     'isFavorite'
26     // ],
27     props: {
3c253f 28         id: {
8480d4 29             title: String,
CM 30             required: true
31         },
fb09dc 32         name: {
CM 33             title: String,
34             required: true
35         },
36         phoneNumber: {
37             title: String,
38             required: true
39         },
40         emailAddress: {
41             title: String,
42             required: true
43         },
44         isFavorite: {
c4371d 45             title: Boolean,
fb09dc 46             required: false,
c4371d 47             default: false,
CM 48             // validator: function (value) {
49             //     return value === '1' || value === '0';
50             // }
fb09dc 51         },
CM 52     },
1630a9 53     emits:['toggle-favorite', 'delete'],
3c253f 54     // emits: {
CM 55     //     'toggle-favorite': function (id) {
56     //         if (id) {
57     //             return true;
58     //         } else {
59     //             return false;
60     //         }
61     //     }
62     // },
f31b9e 63     data() {
CM 64         return {
65             detailsAreVisible: false,
66         }
67     },
68     methods: {
69         toggleDetails() {
70             this.detailsAreVisible = !this.detailsAreVisible;
71         },
7b062d 72         toggleFavorite() {
8480d4 73             this.$emit('toggle-favorite', this.id);
7b062d 74         },
1630a9 75         // deleteFriend(){
CM 76         //     this.$emit('delete', this.id);
77         // }
f31b9e 78     },
CM 79 };
80 </script>