How to get data from an undefined number of inputs?

  • 0
    If there is HTML like
    <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>

    How can I use Vue to get the contents of the fields named k1 that are in the block with id container as a list (one-dimensional array)?
    The number of inputs is unknown.
    Vue.js Cora Taylor, Jan 6, 2020

  • 1 Answers
  • 0
    1. id is a unique identifier, it must be in one instance.

    2. In vue, an undefined number of inputs looks 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.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!