Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda