06 vue 计算属性

6/27/2021 vue

计算属性有缓存功能,而方法每次调用都会执行。

计算属性和侦听器 — Vue.js (opens new window)

API — computed (opens new window)

计算属性的 setter

计算属性的 setter (opens new window)

计算属性的完整写法:

computed: {
  fullName: {
    // getter
    get: function () {
      return this.firstName + ' ' + this.lastName
    },
    // setter
    set: function (newValue) {
      var names = newValue.split(' ')
      this.firstName = names[0]
      this.lastName = names[names.length - 1]
    }
  }
}
更新时间: Sunday, June 27, 2021 17:45