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

109
Views
Calling method in my store returns empty observer object

I am new with Vue.

I have a Vue component like below. The return value of my function getBuildingsByOwnerRequest is unexpected: It returns an empty observer object. Only if I run getBuildingsByOwnerRequest again I receive the expected output from my store action.

Could this be a reactivity problem?

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
    };
}

buildings.js (store):

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

The object is empty at the time it's logged. All asynchronous actions should return a promise:

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

A promise needs to be awaited before accessing results that it promises:

 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!