0

Below is my code.This is not working because i want to make a dynamic key of object.

<li v-for="index in 6" :key="index"> 
    <div class="input-fld">
        <div class="field">
            <p class="control has-icons-right">
                <input type="text" v-model="formData[0].'line_'{{index}}'_text'"/> 
            </p>
        </div>
    </div>         
</li>

I want like this

<input class="input" type="text" v-model="formData[0].line_1_text"/>
<input class="input" type="text" v-model="formData[0].line_2_text"/>
<input class="input" type="text" v-model="formData[0].line_3_text"/>
<input class="input" type="text" v-model="formData[0].line_4_text"/>
<input class="input" type="text" v-model="formData[0].line_5_text"/>
<input class="input" type="text" v-model="formData[0].line_6_text"/>

1 Answer 1

2

Try to set custom names by bracket notation:

<li v-for="index in 6" :key="index"> 
<div class="input-fld">
    <div class="field">
        <p class="control has-icons-right">
            <input type="text" v-model="formData[0]['line_' + index + '_text']"/> 
        </p>
    </div>
</div>         

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.