Cristiano Magro
2024-12-29 3c253f4762ad65990ee19523c625f908eaf17899
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: {
3c253f 27         id: {
8480d4 28             title: String,
CM 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     },
3c253f 52     emits:['toggle-favorite'],
CM 53     // emits: {
54     //     'toggle-favorite': function (id) {
55     //         if (id) {
56     //             return true;
57     //         } else {
58     //             return false;
59     //         }
60     //     }
61     // },
f31b9e 62     data() {
CM 63         return {
64             detailsAreVisible: false,
65         }
66     },
67     methods: {
68         toggleDetails() {
69             this.detailsAreVisible = !this.detailsAreVisible;
70         },
7b062d 71         toggleFavorite() {
8480d4 72             this.$emit('toggle-favorite', this.id);
7b062d 73         },
f31b9e 74     },
CM 75 };
76 </script>