Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

felloz's avatar

Can I use ref() in an object?

<script setup>
let edit = {
	name: ref(false),
	lastName: ref(false)
}
</script>

<template>
<div v-if="!edit.name">show this</div>
</template>

But is not working, show nothing.

0 likes
1 reply
Hzu's avatar
Hzu
Best Answer
Level 2

You can wrap the object in a reactive():

// should work with ref() as well
const edit = reactive({name: false, lastName: false});

Or make the two separate ref() variables outside of the object and assign them inside it:

const name = ref(false);
const lastName = ref(false);

let edit = {
    name: name,
    lastName: lastName
}
1 like

Please or to participate in this conversation.