计算属性与监听属性

46 阅读1分钟

data() {
return {
firstName: '',
lastName: ''
};
},

计算属性

computed: {  
  fullName: function() {  
    return this.firstName + ' ' + this.lastName;  
  }  
},

监听属性

watch: {  
  firstName(newVal) {  
    this.fullName = newVal + ' ' + this.lastName;  
  },  
  lastName(newVal) {  
    this.fullName = this.firstName + ' ' + newVal;  
  }  
}