- computed 的属性不能作为函数使用 ,
- filter 的方法可以作为函数使用
- watch 的属性函数
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]
}
}
}
watch: {
// 如果 question 发生改变,这个函数就会运行
question: function (newQuestion) {
this.answer = ‘Waiting for you to stop typing…’
this.getAnswer()
}
},
这个两个都能解决组件传递数据时的异步