Cristiano Magro
2024-12-28 8480d4ef05d995ee67c1460cf273c899fa59e89c
07 - development setup/vue-cli-01-a-new-vue-project/src/App.vue
@@ -5,14 +5,14 @@
    </header>
    <ul>
      <friend-contact 
      name="Manuel Lorenz"
      phone-number="123"
      email-address="cicio@ciccio.it"
      ></friend-contact>
      <friend-contact
      name="Jeany Torpedo"
      phone-number="123123"
      email-address="torpedo@ciccio.it"
      v-for="friend in friends"
      :key="friend.id"
      :id="friend.id"
      :name="friend.name"
      :phone-number="friend.phone"
      :email-address="friend.email"
      :is-favorite="friend.isFavorite"
      @toggle-favorite="toggleFavoriteStatus"
      ></friend-contact>
    </ul>
  </section>
@@ -28,16 +28,26 @@
          name: "Manuel Lorenz",
          phone: "01234 5678 991",
          email: "manuel@localhost.com",
          isFavorite: true,
        },
        {
          id: "julie",
          name: "Julie Jones",
          phone: "09876 543 221",
          email: "julie@localhost.com",
          isFavorite: true,
        },
      ],
    }
  },
  methods:{
    toggleFavoriteStatus(friendId){
      const found = this.friends.find(
        (friend) => friend.id === friendId
      );
      found.isFavorite = !found.isFavorite;
    }
  }
};
</script>