| | |
| | | <template> |
| | | <li> |
| | | <h2>{{ name }}</h2> |
| | | <h2>{{ name }} {{ friendIsFavorite === "1" ? '(Favorite)' : '' }}</h2> |
| | | <button @click="toggleDetails"> |
| | | {{ detailsAreVisible ? 'Hide' : 'Show' }} Details |
| | | </button> |
| | | |
| | | <button @click="toggleFavorite"> |
| | | Toggle favorite |
| | | </button> |
| | | <ul v-if="detailsAreVisible"> |
| | | <li><strong>Phone:</strong> {{ phoneNumber }}</li> |
| | |
| | | |
| | | <script> |
| | | export default { |
| | | props: [ |
| | | 'name', |
| | | 'phoneNumber', |
| | | 'emailAddress', |
| | | ], |
| | | // props: [ |
| | | // 'name', |
| | | // 'phoneNumber', |
| | | // 'emailAddress', |
| | | // 'isFavorite' |
| | | // ], |
| | | props: { |
| | | name: { |
| | | title: String, |
| | | required: true |
| | | }, |
| | | phoneNumber: { |
| | | title: String, |
| | | required: true |
| | | }, |
| | | emailAddress: { |
| | | title: String, |
| | | required: true |
| | | }, |
| | | isFavorite: { |
| | | title: String, |
| | | required: false, |
| | | default: '0', |
| | | validator: function (value) { |
| | | return value === '1' || value === '0'; |
| | | } |
| | | }, |
| | | }, |
| | | |
| | | data() { |
| | | return { |
| | | detailsAreVisible: false, |
| | |
| | | name: "Manuel Lorenz", |
| | | phone: "01234 5678 991", |
| | | email: "manuel@localhost.com", |
| | | } |
| | | }, |
| | | friendIsFavorite: this.isFavorite, |
| | | } |
| | | }, |
| | | methods: { |
| | | toggleDetails() { |
| | | this.detailsAreVisible = !this.detailsAreVisible; |
| | | }, |
| | | toggleFavorite() { |
| | | if (this.friendIsFavorite === '1') { |
| | | this.friendIsFavorite = '0'; |
| | | } else { |
| | | this.friendIsFavorite = '1'; |
| | | } |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |