VueJS: Can you tell which last changed object?

2

I'm having the following problem, I need the "back" functionality on a button, if I'm in step2 when I click I go back to step1 and from step3 to step2, you can get the last object inside the date that has been changed?

My idea was to click the button, get the last changed value and change it to true .

data: {
        paso1: false,
        paso2: false,
        paso3: true
},
    
asked by anonymous 08.12.2017 / 14:03

1 answer

0

Just listen to the elements with watch , when you notice that the value has changed, you can change back to true, example ...

new Vue({
      el : "#app",
      data : {
        paso1: false,
        paso2: false,
        paso3: false
      },
      methods : {
        altVal (item) {
          this[item] = 'teste';
        }
      },
      watch : {
        paso1() {
          console.log('valor alterado para : ' + this.paso1);
          this.paso1 = true;
        },
        paso2() {
          console.log('valor alterado para : ' + this.paso2);
          this.paso2 = true;
        },
        paso3() {
          console.log('valor alterado para : ' + this.paso3);
          this.paso3 = true;
        },
      }
    })
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script><divid="app">
      <input type="button" @click="altVal('paso1')" value="paso1">
      <input type="button" @click="altVal('paso2')" value="paso3">
      <input type="button" @click="altVal('paso3')" value="paso2"><br>
      {{paso1}}<br>
      {{paso2}}<br>
      {{paso3}}<br>
    </div>
    
08.12.2017 / 20:44