Skip to content

Using getter setter for value #3659

Answered by XEngine
XEngine asked this question in Q&A
Jan 18, 2022 · 1 comments · 4 replies
Discussion options

You must be logged in to vote
export function useModelBinding(initialValue, emit, opts) {
    const {errorMessage, value} = useField(opts.name, opts.rules, {initialValue});

    const modelBinding = computed({
        get: () => {
            return value.value
        },
        set: (inputValue) => {
            value.value = inputValue
            emit('update:modelValue', value)
        }
    })

    return {
        errorMessage,
        modelBinding
    }
}

used this composable solution for my custom input component. Don't know this is a stable one yet.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@logaretm
Comment options

@stefanzweifel
Comment options

@XEngine
Comment options

@stefanzweifel
Comment options

Answer selected by XEngine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3657 on January 19, 2022 09:08.