vue.js入门教程之计算属性

2020-06-16 06:34:07易采站长站整理
方法,那么有没有
set
方法呢?


// ...
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] }
}
}
// ...

如果我们调用

vm.fullName = 'John Doe'
时,
setter 
就会被调用。
vm.firstName
vm.lastName
也会有相应更新。这个方法,在有些时候是很有用的。

总结

以上就是关于vue.js计算属性的全部内容,希望这篇文章对大家能有所帮助,小编还会陆续更新关于vue.js的内容,感兴趣的小伙伴们可以继续关注软件开发网。