vue異なるイベントを動的にバインドするには

12419 ワード

vue異なるイベントを動的にバインドするには
今日、業務要求クーポンに異なるデータの詳細を要求され、あるクーポンは初めてクリックしてテキストボックスをポップアップすることができ、2回目のクリックは許可されず、3回持っていくことができる(典型的なパリティクリック).次に右下に総ボタンがあり、奇数ですべてのクーポンをクリックすると表示され、偶数はすべて失効します.あなたたちが理解しているかどうか分かりませんが、どうせ私たちの業務はこのように言っています(ここにデータがないので、私は偽のデータでします).わかりました.いいですよ.くだらないことを言わないで、直接コードをつけます.
  <template>
  <div id="app">
    <div class="dynamic">
      <button
        class="dynamic-item"
        v-for="(item,index) in list"
        :key="index"
        v-on:[eventName]="handleClick(item.doSome,index)"
      >       --{{item.doSome}}</button>
    </div>
    <button @click="allClick">        </button>
  </div>
</template>
<script>
	export default {
	  name: "app",
	  data() {
	    return {
	      list: [
	        { doSome: "doSomg1" },
	        {  doSome: "doSomg2" },
	        { doSome: "doSomg3" },
	        { doSome: "doSomg4" },
	        {  doSome: "doSomg5" },
	        { doSome: "doSomg6" }
	      ],
	      eventName: "click",
	      newArrys: new Array(5),
	    };
	  },
	  mounted() {
	    var s = new Array(5);
	    console.log(this.newArrys);
	  },
	  methods: {
	    handleClick(i, inedx) {
	      let doSomes = i;
	      this[doSomes](inedx);
	    },
	    doSomg1(inedx) {
	      this.newArrys[inedx] = !this.newArrys[inedx];
	      if (this.newArrys[inedx]) {
	        console.log("doSomg1", this.newArrys[inedx]);
	      }
	    },
	    doSomg2(inedx) {
	      console.log("doSomg2");
	    },
	    doSomg3(inedx) {
	      console.log("doSomg3");
	    },
	    doSomg4(inedx) {
	      console.log("doSomg4");
	    },
	    doSomg5(inedx) {
	      console.log("doSomg5");
	    },
	    doSomg6(inedx) {
	      console.log("doSomg6");
	    },
	    allClick(){
	      this.eventName=='click'? this.eventName=null: this.eventName='click'
	    }
	  }
	};
</script>