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

176
Views
Why method in in mixin returns object Promise?

In vuejs3 app I want to use common method, so I put it into mixin resources/js/appMixin.js as :

export default {

    methods: {

        async getBlockPage(page_slug) {
            const response = await axios.post('/get_block_page', {slug: this.page_slug})
            console.log('response.data.page::')
            console.log(response.data.page) // In the browser console I see this valid page object returned


            return response.data.page;

        }, // getBlockPage() {

but calling this method in vue file :

mounted() {
    this.about= this.getBlockPage("about");
    console.log('AFTER this.about::') // I DO NOT this output
    console.log(this.about)
},

and outputting about var I see

"[object Promise]"

Which is the valid way?

That question seems a bit specific then provided link, as method is inside of mixin...

Thanks in advance!

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

0

Yes sure, getBlockPage is an async function, always return Promise.

async mounted() {
  this.about= await this.getBlockPage("about");
  console.log(this.about)
},

or

mounted(){
  this.getBlockPage("about")
    .then(result => {
       console.log(result);
    )
    .catch(error => {
      //error handler
    });
}

You can learn more here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

Async / await is just a syntaxic sugar for define Promise behavior on your function

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!