0

vue 2.5.3 数组双向绑定的问题,页面修改数据input的值,myarr的值没有改变

<div id='app'>
<div  v-for="(item,index) in myarr" :key="index">
    name:<input :key="index" v_model='myarr[index].name' @input="changed" /> id:{{item.id}}
</div>
</div>

    <script>
        var a = {id:1,name:'1'};
        var app = new Vue({
          el: '#app',
          data: {
            message: 'Hello Vue!',
            list:[{id:1,text:'a'},{id:2,text:'b'}],
            indexarr:[],
            myarr:[{id:1,name:'1'}],
                      total:'0'
          },
          methods:{    
            computeNumber:function(){
                this.myarr.push(a);
            },
            changed:function(){
                var num = 0;
                $(this.myarr).each(function(index,item){
                    num += Number(item.name);
                });
                this.total = num;
            },
            watchmyarr:function(){
                console.log(JSON.stringify(this.myarr) );
                return this.myarr;
            }
          }
        })
    </script>

查看全部 4 个回答

0

是否没有触发computeNumber函数?