I have a Vue3 component where, within the setup()
, I have defined the following function:
const writeNote(note: Ref<Note>) => { console.log(`note ${note.id}`) }
This function takes a Ref<Note>
, with Note
being an Interface.
There are two scenarios in which this function is called:
- Firstly, in the template from a component event (
@modified-note='writeNote'
), passing a reference to the function - Secondly, in a function within
setup()
that retrieves instances of typeNote
and passes them towriteNote
. In this case, a regular variable (not a reference) is passed.
How can this inconsistency be resolved?
- In the template call, could the sent value be somehow "un-referenced"? (in which case, the argument type in the function would need to be changed to just
Note
) - In the
setup()
call, could a normal variable be transformed into a reference for this specific purpose?