Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vue3 counter and const form in setup()

I don’t understand, please help.
I have a counter that works through a setup, and I also have a form that is in the same setup, how can I combine them?

My code:

setup(props) {
    const form = useForm({
        name: props.user.name,
    })
    function update_shopItem() {
        form.put(route('user.update', props.user.id))
    }
    return { form, update_shopItem }
    
    
    
    const count = ref(1)
    return {
        count
    };

},

I know that this is because there are two returns and only the first one is executed and after the code is interrupted, but how can I make it work otherwise that all the code inside the setup was executed? Tell me please.
I want to make the counter work regardless of the const form.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could just use one return that takes the different properties :

setup(props) {
    const form = useForm({
        name: props.user.name,
    })
    function update_shopItem() {
        form.put(route('user.update', props.user.id))
    }

    const count = ref(1)

    return { form, update_shopItem, count}
},
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading