Search code examples
vue.jsv-model

v-modal with a multi part variable


I'm not sure if this is the correct way to ask this, but I'm having trouble setting up a v-model that has multiple parts.

v-model="formInputs.input_ + inputType.id"

That would end up being this in the data:

data(){
    return {
        formInputs: {
            input_(its id here): ''
            //example input_5
        },
    }
},

Is it possible to chain values inside a v-model?


Solution

  • You can use [] instead of . as key accessor:

    v-model="formInputs['input_' + inputType.id]"