Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Data not available outside of onBeforeMount - Composition API / Vue 3

In the single code component, I have the following script:

<script setup lang="ts">
import ApiService from '../service/api'
import { reactive, onBeforeMount } from 'vue'

let pokemons = reactive([])

onBeforeMount(async ()=> {
  const response = await ApiService.getAll()
  pokemons = response.data.results
  return pokemons
})
</script>

Pokemons inside the OnBeforeMount exist, but not outside of it.

Any tips?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. onBeforeMount's callback function does not require a return value
  2. reactive is meant to be used as a proxy to a ref value to watch all of the ref's nested properties.
<template>
<ul>
  <li v-for="p in pokemons" :key="p.id">{{ p.name }}</li>
</ul>
</template>

<script setup lang="ts">
import ApiService from '../service/api'
import { reactive, onBeforeMount, ref } from 'vue'

const allPokemon = ref([])
const pokemons = reactive(allPokemon)

onBeforeMount(async ()=> {
  const response = await ApiService.getAll()
  allPokemon.value = response.data.results
})
</script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!