Skip to content

4 - writable-computed #2921

@ricardoHer

Description

@ricardoHer
// your answers
<script setup lang="ts"> import { ref, computed } from "vue" const count = ref(1) const plusOne = computed({ get() { return count.value + 1 }, set(newValue) { count.value = newValue; } }) /** * Make the `plusOne` writable. * So that we can get the result `plusOne` to be 3, and `count` to be 2. */ plusOne.value++ </script>

Activity

suleiman-hamza

suleiman-hamza commented on Apr 1, 2025

@suleiman-hamza

In the set() method, we need to subtract 1 from the newValue to maintain consistency with the getter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ricardoHer@suleiman-hamza

        Issue actions

          4 - writable-computed · Issue #2921 · webfansplz/vuejs-challenges