computed

computed

  • Type: Object

  • Details:

    Computed properties to be mixed into the Vue instance. All getters and setters have their this context automatically bound to the Vue instance.

  • Example:

    var vm = new Vue({
      data: { a: 1 },
      computed: {
        // get only, just need a function
        aDouble: function () {
          return this.a * 2
        },
        // both get and set
        aPlus: {
          get: function () {
            return this.a + 1
          },
          set: function (v) {
            this.a = v - 1
          }
        }
      }
    })
    vm.aPlus   // -> 2
    vm.aPlus = 3
    vm.a       // -> 2
    vm.aDouble // -> 4
  • See also:

doc_VueJS
2016-09-25 05:48:04
Comments
Leave a Comment

Please login to continue.