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

82
Visualizações
Create an instance of a composable

I created a little composable, which is supposed to help me handling modals and slide overs.

This is the composable :

export function useSlideover() {

    const isOpen = ref(false);

    function toggle(){
        isOpen.value = !isOpen.value;
    }

    function open(){
        isOpen.value = true;
    }

    function close(){
        isOpen.value = false;
    }

    return { isOpen,  toggle, open, close}
}

export function useModal() {

    const isOpen = ref(false);

    function toggle(){
        isOpen.value = !isOpen.value;
    }

    function open(){
        isOpen.value = true;
    }

    function close(){
        isOpen.value = false;
    }

    return { isOpen,  toggle, open, close}
}

If I use it in a component like this :

const {isOpen, open, close, toggle} = useSlideover();

...

open();

everything works nice. But from time to time, there are two components using this composable at the very same time - e.g. there is a modal that opens a smaller modal.

What happens here is that if I use the close() function on the smaller modal, the parent-modal closes too, as isOpen changes to false for this component, too.

My question is: How can I handle the state of each modal individually ?

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

0

You can rewrite the useModal and pass the ref of the modal you want to show/hide

export function useModal() {

    function toggle(isOpen){
        isOpen.value = !isOpen.value;
    }

    function open(isOpen){
        isOpen.value = true;
    }

    function close(isOpen){
        isOpen.value = false;
    }

    return {toggle, open, close}
}

and in the setup use it like this

const mod = ref(false)
const innerMod = ref(false)

const {open, close, toggle} = useModal(); 

open(mod)

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