Cristiano Magro
2024-12-28 c4371db9541bc6463d58193f9a60542e35cc3204
commit | author | age
f31b9e 1 <template>
CM 2     <li>
c4371d 3         <h2>{{ name }} {{ friendIsFavorite ? '(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: {
27         name: {
28             title: String,
29             required: true
30         },
31         phoneNumber: {
32             title: String,
33             required: true
34         },
35         emailAddress: {
36             title: String,
37             required: true
38         },
39         isFavorite: {
c4371d 40             title: Boolean,
fb09dc 41             required: false,
c4371d 42             default: false,
CM 43             // validator: function (value) {
44             //     return value === '1' || value === '0';
45             // }
fb09dc 46         },
CM 47     },
48
f31b9e 49     data() {
CM 50         return {
51             detailsAreVisible: false,
7b062d 52             friendIsFavorite: this.isFavorite,
f31b9e 53         }
CM 54     },
55     methods: {
56         toggleDetails() {
57             this.detailsAreVisible = !this.detailsAreVisible;
58         },
7b062d 59         toggleFavorite() {
c4371d 60             this.friendIsFavorite = !this.friendIsFavorite;
7b062d 61         },
f31b9e 62     },
CM 63 };
64 </script>