<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 commentedon Apr 1, 2025
In the set() method, we need to subtract 1 from the newValue to maintain consistency with the getter