Vuejs: is it possible to know which was the last object changed?

Asked

Viewed 139 times

2

I have the following problem, I need the functionality of "back" in a button, if I am in the foot2 when I click I go back to the foot1 and from the foot3 to the foot2, it is possible to pick up the last object inside the date which has been amended?

My idea was to click the button, take the last altered value and change it to true.

data: {
        paso1: false,
        paso2: false,
        paso3: true
},

1 answer

0

Just listen to the elements with watch, when realizing that the value has been changed, it is possible to change again 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>
    <div id="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>

  • the problem is that I need to click only one button and check only which was the last item changed, regardless if it is step 1,2 or 3

  • It would be better if you explain what you want to do, because you may have a more appropriate solution, after all each time you make some change the same will point to the date object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.