Vuejs: v-model array in multiple input

前端 未结 3 1054
一个人的身影
一个人的身影 2021-01-30 20:16

I have an input text field with a v-model attached, and every time someone hits the \"Add\" button, another input text get added to the DOM with the same v-model attached. I tho

3条回答
  •  不要未来只要你来
    2021-01-30 20:59

    Here's a demo of the above:https://jsfiddle.net/sajadweb/mjnyLm0q/11

    new Vue({
      el: '#app',
      data: {
        users: [{ name: 'sajadweb',email:'sajadweb@outlook.com' }] 
      },
      methods: {
        addUser: function () {
          this.users.push({ name: '',email:'' });
        },
        deleteUser: function (index) {
          console.log(index);
          console.log(this.finds);
          this.users.splice(index, 1);
          if(index===0)
          this.addUser()
        }
      }
    });
    
    

    Add user

    {{ $data }}

提交回复
热议问题