Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda