Level 1
I ended up using ref. What I was missing was instead of orders = res.data I needed to use orders.value = res.data
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have this script in a Vue 3 component. The console.log actually shows 9 orders, but when I add {{orders}} to the page, all I see is an empty array. That's also what I see in the setup dropdown of the Vue devtools
<script setup>
import axiosInstance from "../../helpers/axios";
import {onMounted} from "vue";
onMounted(() => {
getOrders()
})
let orders = [];
async function getOrders() {
try {
const res = await axiosInstance.get("/api/orders")
if(res.status === 200) {
orders = res.data
}
console.log(orders)
} catch (error) {
console.log(error)
}
}
</script>
I also tried
...
import {ref} from "vue";
let orders = ref([]);
...
Please or to participate in this conversation.