We're using the Vue Composition API and would like to pass a ref object, not just the value, as an argument to a function. Some code to clarify:
import { defineComponent, ref } from '@vue/composition-api'
export default defineComponent({
setup() {
const driverId = ref()
const truckId = ref()
const clearDriverId = () => {
driverId.value = null
}
The code above works fine, but we need to duplicate the function clearDriverId for the truckId too. That's why we would like to create something like this:
const clearField = (field: Ref) => {
field.value = null
}
Accessed from the template:
<q-input
label="Driver ID"
v-model="driverId"
>
<template v-slot:append>
<q-icon
name="close"
@click.stop="clearField(driverId)"
/>
</template>
</q-input>
Of course, this does not work because the ref driverId gets unwrapped when passed from the template to the function. What is the correct way to pass a complete ref object to a function?