I used vue 2 quiet a lot and now finally trying to slowly using vue 3 but I am already kind of buffled of how this works. In vue 2, I used the created method to fetch API data and populate my data arrays. Now I was trying the vue 3 way by using onMounted and I can log the API response. What I dont seem to find out is, how can I make my streams array to be initialized by the json response from the API now?
<script setup lang="ts">
import { ref, onMounted } from "vue";
let streams = ref(); //should be array of Objects {marketId, timeframe}
onMounted(() => {
fetch("http://localhost:3000/stream")
.then((response) => response.json())
.then((result) => (streams.value = result)); //json response array {marketId, timeframe}, {marketId, timeframe}
console.log(streams.value); //returns undefined
});
</script>