[Vuejs]-Problems with reactivity and computed properties Vue 3 – Composition API

0👍

The error message you are getting is because a computed by default is a getter.

In the setup() with a standalone computed they show the following example:
Example

const count = ref(1)
const plusOne = computed({
  get: () => count.value + 1,
  set: (val) => {
    count.value = val - 1
  },
})

plusOne.value = 1
console.log(count.value) // 0 
  • So, where do you define the ref()?
  • You can get the value of the ref with .value

Computed getters/setters like this in the Options API:

let filter = computed({
            get() {
                console.log('get');
                return createFilter(route.params);
            },
            set(newValue: any) {
                console.log('set');
                route.params = newValue;
            },
        });

Leave a comment