unref()
Returns the inner value if the argument is a ref, otherwise the value.
Syntax
unref<T>(maybeRef: T | Ref<T>): T Parameters
| Name | Type | Required | Description |
|---|---|---|---|
maybeRef | T | Ref<T> | No | A ref or a plain value. |
Returns
T — The unwrapped value (val = isRef(r) ? r.value : r).
Examples
<script setup lang="ts">
import { ref, unref } from 'vue';
function double(input: number | { value: number }) {
return unref(input as any) * 2;
}
const n = ref(5);
console.log(double(n)); // 10
console.log(double(7)); // 14
</script>
Notes
unref is sugar for `isRef(x) ? x.value : x`, useful when a function should
accept either a ref or a raw value. It does not create reactivity tracking by
itself; read inside a reactive scope if you need tracking.