Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

81
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!