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

153
Visualizações
Await in vue3 function for button click

Hello I am trying to await a button click inside a vue3 method, I basically want to click a button to start the function and then wait till the "confirm" or "cancel" button is clicked by the user, I am using the vue3 developer CDN (if that information is useful) Here's what I have so far:

<div v-if="hasAccess('FTO') && !selectedPlayerLoading" id="ftosheet-container">
    <div class="ftosheet-title noselect">FTO Sheet 
        <span v-if="hasAccess('FTO')" v-on:click='editFTOSheet()' style="float: right;">
            <i class="fas fa-edit"></i>
        </span>
    </div>

    <textarea class="ftosheet-text" v-model="selectedPlayer.ftosheet" :readonly="editingFTOSheet === false">
    </textarea>
    <div id="ftobutton-container">
        <button v-if="editingFTOSheet" id="saveftobutton">Save FTO Sheet</button>
        <button v-if="editingFTOSheet" id="cancelftobutton">Cancel</button>
    </div>
</div>
OnButtonPress() {
    Vue.nextTick(function () {
        return new Promise((resolve) => {
            const confirm = document.getElementById('saveftobutton')
            confirm.addEventListener('click', function() {
                resolve(true);
            });
            const deny = document.getElementById('cancelftobutton')
            deny.addEventListener('click', function() {
                 resolve(false);
            });
        });
    })
},

async editFTOSheet() {
    this.editingFTOSheet = !this.editingFTOSheet;
    if (this.editingFTOSheet) {
        const uneditedSheet = this.selectedPlayer.ftosheet;
        const buttonPress = await this.OnButtonPress();
        console.log(buttonPress);
        //TODO: Make work with await button press
    }
},

Obviously because the buttons only get rendered after clicking the "edit" button I need the nextTick I think? VS Code is also telling me that await has no effect here. Console prints undefined instantly after calling the OnButtonPress() function. Please let me know if you need any more information, Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

        OnButtonPress() {
        return new Promise((resolve) => {
            Vue.nextTick(function () {
                const confirm = document.getElementById('saveftobutton')
                confirm.addEventListener('click', function() {
                    resolve(true);
                });
                const deny = document.getElementById('cancelftobutton')
                deny.addEventListener('click', function() {
                    resolve(false);
                });
            });
        });
    },

Had to put the return before Vue.nextTick.

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