In my setup, I have the following:
const{ data, error } = useFetch("http://localhost:8080/articles", { query: { page: dataPage }})
where datapage
is a ref. This refetches whenever I change datapage
, so that works well.
Now I want to get a field out of the data
variable. Specifically, this works:
<div>{{ data.pageable }}</div>
But I want to do this:
const pageable = toRef(data.pageable)
...
<div>{{ pageable }}</div>
This returns nothing (undefined). I also tried:
const { pageable } = toRefs(data)
with no luck.
How can I make a field of the data
into a reactive value?
Basically, I'm trying to avoid referencing "data" each time I want to access a field of the fetched data object.
Edit. I completely missunderstood OP's question.
If you are trying to avoid referencing the
data
, you can use the computed property.~/pages/index.vue
API example
~/server/api/get-the-query