码迷,mamicode.com
首页 > 编程语言 > 详细

数组内部的对象监听问题

时间:2019-03-11 15:02:03      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:form   func   this   方法   over   inpu   --   value   click   

<div class="test-form"  :key="index"  v-for="(item, index) in arrs">

  <input v-model="item.test_id" @input="changeFunc(item,index)" />  <!-- 如果不加上@input中的方法,那么新增出来input的value会同步一样 -->

</div>

<button @click="addArrHandler"></button>

data(){

  arrs : [ ],  //数组

  arrs_item:{

    test_id: ‘ ‘,

    goals: ‘ ‘,

  }

},

methods:{

  addArrHandler(){

    this.arrs.push(this.arrs_item);

  },

  changeFunc(item, index){

    this.arrs[index].test_id = item.test_id;

    this.watchVal();

  },

  watchVal(){

    const arrs = this.coverage_tests;
    if(arrs.length > 0){
      for(let i=0; i<arrs.length; i++){
        let test_id = arrs[i].test_id;
        this.$set(this.coverage_tests[i], ‘test_id‘, ‘‘);
      }
    }

  }

}

 

数组内部的对象监听问题

标签:form   func   this   方法   over   inpu   --   value   click   

原文地址:https://www.cnblogs.com/haishen/p/10510504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!