Vue click the button to dynamically add input and get the value entered by input

Click the button once to dynamically add an input, to get the value of the input input when the input input is worth it

Sep.24,2021

when you click the button, add a text box and bind the event at the same time. When you change, the output value will be fine

the following is a sample code for vue

<template>
  <div>
    <input type="text" v-for="(item,i) of items" v-model="items[i]" :key="i">
    <button @click="onAdd"></button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: []
    }
  },
  methods: {
    onAdd() {
      this.items.push('')
    }
  }
}
</script>
Menu