2017-01-15 8 views

答えて

1

何が間違ってやっていることは、あなたがactiveプロパティを変更することであり、それはすべてのためreflectedです:どのように私は、現在のインデックス(?トグル方式)ここ

var app = new Vue({ 
    el: '#app', 
    data: { 
    inputProject: [], 
    counter:0, 
    active : false 
    }, 
    methods: { 
    addInput: function() { 
      this.inputProject.push(this.counter); 
      this.counter++ 
     }, 
    removeInput: function(index) { 
      this.inputProject.splice(index,1); 
     }, 
    toggle: function (index) { 
     this.active = !this.active; 
    } 
    } 
}) 

enter image description here

Jsfiddleのみ呼び出すことができます要素。

解決策は、オブジェクトごとにactiveプロパティを割り当て、v-showディレクティブを使用することです。

<p v-show="elem.active" v-bind:id="elem.id">show {{push}}</p> 

working fiddle.

var app = new Vue({ 
    el: '#app', 
    data: { 
    inputProject: [], 
    counter:0 
    }, 
    methods: { 
     addInput: function() { 
     this.inputProject.push({id:this.counter,active:false}); 
     console.log(this.inputProject); 
     this.counter++ 
     }, 
     removeInput: function(index) { 
     this.inputProject.splice(index,1); 
     }, 
     toggle: function (index) { 
     var item= this.inputProject.filter(a=>a.id==index)[0]; 
     item.active=!item.active; 
     } 
    } 
}) 
関連する問題