[Vuejs]-VUE- computed function for updating variables

4👍

Because, computed contains the properties, something which returns a value, rather than an even handler.
Event handler are closures which should be captured inside the methods.

Have a look at sample example from Vue.js docs:

var vm = new Vue({
  el: '#example',
  data: {
    message: 'Hello'
  },
  computed: {
    // a computed getter
    reversedMessage: function () {
      // `this` points to the vm instance
      return this.message.split('').reverse().join('')
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="example">
  <p>Original message: "{{ message }}"</p>
  <p>Computed reversed message: "{{ reversedMessage }}"</p>
</div>

Here, reversedMessage is used just like a normal data property in your DOM, but is infact tied to other data properties.

while in your case, updatekey is clearly a handler, which needs to make some changes or do some computations when an event is triggered.

Leave a comment