On my App.vue file I have this object being provided:
let myObject = ref(null)
provide('myObject', myObject)
In a component file I have this object being injected like this:
const myObject = inject('myObject')
below I have this variable:
let myVariable = null
When I make myVariable
equal to value of myObject
and then change a key value on myVariable
, the same key value changes in myObject
and when I run this:
console.log(myObject.value)
console.log(myVariable)
myVariable = myObject.value
console.log(myObject.value)
console.log(myVariable)
myVariable.symbol = 'new value'
console.log(myObject.value)
console.log(myVariable)
I see that myObject
and myVariable
appear to inherit the same changes.
How can I make it so that myVariable
becomes a copy of myObject
without being linked to myObject
so I can manipulate it independently?