1// ...
2computed: {
3 fullName: {
4 // getter
5 get: function () {
6 return this.firstName + ' ' + this.lastName
7 },
8 // setter
9 set: function (newValue) {
10 var names = newValue.split(' ')
11 this.firstName = names[0]
12 this.lastName = names[names.length - 1]
13 }
14 }
15}
16// ...
1var vm = new Vue({
2 el: '#example',
3 data: {
4 message: 'Hello'
5 },
6 computed: {
7 // a computed getter
8 reversedMessage: function () {
9 // `this` points to the vm instance
10 return this.message.split('').reverse().join('')
11 }
12 }
13})