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

253
Vistas
How to inject JavaScript into Vue script

I have a block of code that needs to be reused in multiple components. What is the best way to do this in Vue 3 with the composition API and script setup? I've looked into composables, but I can't get it to work for my use case. My code is a bit like this

const popupEnabled = ref(false);

function currentPopupState() {
    return store.getters.getPopupState;
}

onMounted(() => {
    watch(currentPopupState, (value) => {
        if (value) {
            popupEnabled.value = true;
            setTimeout(() => {
                store.commit("changeCurrentPopupState", false);
                popupEnabled.value = false;
            }, 1800);
        }
    });
});

It watches an external value, then runs a timed function if the value is changed. I just want to inject this block of code into my Vue script, how do I do this?

about 4 years ago · Juan Pablo Isaza
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