I am trying to get data from an API and want to reuse it inside my script. I am using a ref to store the data. Usually i can access my data via myRef.value. But i do observe some behaviour that makes it complicated to access my data inside the proxy.
This is my request inside a composable.
export default function (url) {
const data = ref([]);
const count = ref(0);
const page = ref(1);
const isLoaded = ref(false);
const getUrl = computed(() => {
if (page.value > 1) {
return `${url}?page=${page.value}`;
} else return url;
});
watchEffect(async () => {
axios({
url: getUrl.value
})
.then((res) => {
data.value = res.data.results;
count.value = res.data.count;
isLoaded.value = true;
})
.catch((err) => console.log(err));
});
const updatePage = (newPage) => {
page.value = newPage;
};
return {
data: data,
count,
page,
updatePage
};
}
The output of those 2 logs is the following:
So what is happening here? I assigned red.data.results to data.value. But logging those 2 gives different results. Accessing a ref's .value should return the proxy's content, but here we see a proxy again.
I do find workarounds, but i would like to understand before i avoid this.