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

Udev's avatar
Level 2

Add/Update property to vue 3 ref object

How can I add(or update if exists) a property to ref object. I have tried the the following:

cont object = ref({})
const addOrUpdateObject = (key,val) => {
	object.value[key] = val
})

I get error "Cannot set properties of null"

0 likes
2 replies
martinbean's avatar

@udev You’d be better off creating a reactive object to track property changes:

const foo = reactive({});

foo[key] = value;
Udev's avatar
Udev
OP
Best Answer
Level 2

@martinbean can't do that in my case as the properties are dynamic. Managed to find a workaround where I create a temporary object then replace the whole ref object, i.e.,

cont object = ref({})
const todo= () => {
	let temp = {}

	//todo loop
	    temp[key] = val

	object.value = temp
})
~~~

Please or to participate in this conversation.