Vue 3: How to combine multiple ref

Viewed 36

How to combine multiple ref value in one:

        const variable1 = ref(false);
        const variable2 = ref('');
        const variable3 = ref(false);
        const variable4 = ref(false);           
        const variable5 = ref(false);
        const variable6 = ref(false);
2 Answers

You can use an object instead:

// Creation
const myValues = ref({
  someVar: true,
  otherValue: false
})

// In code somewhere
myValues.value.someVar = false

Instead you could also use reactive. Replacing the object isn't possibel then though.

Related