R
R
robert_ford2020-11-17 21:02:24
Vue.js
robert_ford, 2020-11-17 21:02:24

How to get data from an indefinite number of inputs?

If there is an HTML of the form

<div id = "container">
<input id = "form-input" name = "k1" type = "hidden">
<input id = "form-input" name = "k1" type = "hidden">
<input id = "form-input" name = "k1" type = "hidden">
...
<input id = "form-input" name = "k1" type = "hidden">
...
</div>

So how can Vue get the contents of the fields named k1 , which are in the block with id container as a list (one-dimensional array) ?
The number of inputs is unknown.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-11-18
@robert_ford

1. id- a unique identifier, it must be in one copy.
2. In vue, an indefinite number of inputs looks something like this:

<div id="container">
  <input v-for="input in inputs" v-model="input.value" :name="input.name" type="hidden" >
</div>
data: {
  inputs: [
    {
      name: 'k1', 
      value: ""
    }, 
    {
      name: 'k2', 
      value: ""
    }
  ]
}
And the values ​​are obtained, respectively, from the array inputs.
In Vue, you work with the data, not the dom, the dom only reflects the state of the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question