B
B
bqio2018-12-14 09:32:29
Vue.js
bqio, 2018-12-14 09:32:29

How to bind object properties in v-for with input?

<div class="panel-item" v-for="(value, key, index) of activeElement" :key="index">
  <input type="text" v-model="activeElement[key]">
</div>

5c134e5f9bb93378410848.png
activeElement[key] doesn't work.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Malkov, 2018-12-14
@MalkovVladimir73

What is key equal to? It's not, by any chance, that you use v-for ... of instead of v-for ... in?

L
Lumore, 2018-12-14
@Lumore

key == index

<div class="panel-item" v-for="(value, key) in activeElement" :key="key">
  <input type="text" v-model="activeElement[key]">
</div>

R
Roman Kitaev, 2018-12-14
@deliro

The object is not bound via v-model. It's better to use an array for this. But if you really want an object, then:
https://jsfiddle.net/gvmo58Lb/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question