Vue filter computed watch 的用法

来源:互联网 发布:同济启明星软件价格 编辑:程序博客网 时间:2024/06/05 20:28
  1. computed 的属性不能作为函数使用 ,
  2. filter 的方法可以作为函数使用
  3. 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()
}
},
这个两个都能解决组件传递数据时的异步

原创粉丝点击