A
A
alaskafx2021-08-24 18:19:08
Vue.js
alaskafx, 2021-08-24 18:19:08

How to find out which key has changed?

inputsRange: {
                noseWidth: 0,
                noseHeight: 0,
                noseTipLong: 0,
                noseTipHeight: 0,
                noseBrake: 0,
                browsHeight: 0,
                browsDept: 0,
                checkboonesHeight: 0,
                nose: 0,
            },


watch: {
    inputsRange:{
        deep: true,
        handler(oldValue, newValue) {
            for (variable in this.inputsRange) { // узнаем названия всех ключей в inputsRange
              }
        }
    }
   }


- how can I find out the name of the key that changed its value?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-08-24
@alaskafx

computed: {
  objCopy() {
    return { ...this.obj };
  },
},
watch: {
  objCopy(newObj, oldObj) {
    for (const [ k, v ] of Object.entries(newObj)) {
      if (v !== oldObj[k]) {
        console.log(`obj.${k} changed from "${oldObj[k]}" to "${v}"`);
      }
    }
  },
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question