Cristiano Magro
2024-12-28 fb09dca31f9a64ca4287579006014157a3d8156c
commit | author | age
f31b9e 1 <template>
CM 2     <li>
7b062d 3         <h2>{{ name }} {{ friendIsFavorite === "1" ? '(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: {
40             title: String,
41             required: false,
42             default: '0',
43             validator: function (value) {
44                 return value === '1' || value === '0';
45             }
46         },
47     },
48
f31b9e 49     data() {
CM 50         return {
51             detailsAreVisible: false,
52             friend: {
53                 id: "manuel",
54                 name: "Manuel Lorenz",
55                 phone: "01234 5678 991",
56                 email: "manuel@localhost.com",
7b062d 57             },
CM 58             friendIsFavorite: this.isFavorite,
f31b9e 59         }
CM 60     },
61     methods: {
62         toggleDetails() {
63             this.detailsAreVisible = !this.detailsAreVisible;
64         },
7b062d 65         toggleFavorite() {
CM 66             if (this.friendIsFavorite === '1') {
67                 this.friendIsFavorite = '0';
68             } else {
69                 this.friendIsFavorite = '1';
70             }
71         },
f31b9e 72     },
CM 73 };
74 </script>