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

113
Views
El método de llamada en mi tienda devuelve un objeto de observador vacío

Soy nuevo con Vue.

Tengo un componente Vue como el siguiente. El valor de retorno de mi función getBuildingsByOwnerRequest es inesperado: devuelve un objeto observador vacío. Solo si vuelvo a ejecutar getBuildingsByOwnerRequest , recibo el resultado esperado de la acción de mi tienda.

¿Podría ser esto un problema de reactividad?

 data() { return { editedOwner = { "owner_id": 12223, } }, } computed: { ...mapState("buildings", ["buildings_by_owner"]), }, methods: { ...mapActions("buildings", ["getBuildingsByOwnerRequest"]), function() { this.getBuildingsByOwnerRequest(this.editedOwner.owner_id); console.log(this.buildings_by_owner) // returns empty observer object ([__ob__: Observer] with length: 0) // if I run the function again I get the expected return }; }

edificios.js (tienda):

 state: { buildings_by_owner: [] }, actions: { getBuildingsByOwnerRequest({ dispatch }, owner_id) { axios .get( `${process.env.VUE_APP_BASE_URL}/get/buildings_by_owner/owner_id=${owner_id}` ) .then((res) => { // API call returns valid json as expected dispatch("receiveBuildingsByOwner", res.data); }); }, receiveBuildingsByOwner({ commit }, payload) { commit("RECEIVED_BUILDINGS_BY_OWNER", payload); }, } mutations: { RECEIVED_BUILDINGS_BY_OWNER(state, payload) { state.buildings_by_owner = payload; }, }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

El objeto está vacío en el momento en que se registra. Todas las acciones asincrónicas deben devolver una promesa:

 getBuildingsByOwnerRequest({ dispatch }, owner_id) { return axios ...

Se debe esperar una promesa antes de acceder a los resultados que promete:

 this.getBuildingsByOwnerRequest(this.editedOwner.owner_id).then(() => { console.log(this.buildings_by_owner) })
about 4 years ago · Santiago Gelvez 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!