How does Vue monitor an object and execute a method when the content of the object changes?

how does Vue monitor an object and execute a method when the content of the object changes?

Mar.03,2021

you can use the watch method in vue to listen to the object. Set deep:true to do deep listening. When the properties in the object change, the handler method will be called, and you can write your logic in it

.
<template>
  <div>
    <input v-model="user.name">
  </div>
</template>

<script>
export default {
  data () {
    return {
      user: {
          name: ''
      }
    }
  },

  watch:{
      user: {
        deep: true,
        handler: function (newVal,oldVal){
          console.log('newValue', newVal);
          console.log('oldValue', oldVal.name);
        }
      }
  },
}

it is recommended that you use watch listening events to complete


., watch: {'params.limit': function (newValue, oldValue) {}, name: function (newValue, oldValue) {}},

suppose you have an object in your ViewModel that is {params: {limit:'}, name:''}


solve this how to monitor?

<table ...>
  ...
  <tbody>
    <tr v-for="(item, index) in items" :key="index" :class="{ actived : selected === index}">
      <td>{{ item.name }}</td>
      <td>
        <input v-if="item.editable" v-model="item.age" type="number" ... />
        <span v-else>{{ item.age }}</span>
      </td>
    </tr>
  </tbody>
</table>

question:
how do I automatically focus on the input box when a row is selected for editing? < td: ref= "'input' + index". > invalid , < tr index for = "(item, index) in items": key= "index": ref= "item". > is also not available through $el.querySelector (' input.number') .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3aaea-2c23d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3aaea-2c23d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?