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// ...
1vm.$watch('person.name.firstName', function(newValue, oldValue) {
2 alert('First name changed from ' + oldValue + ' to ' + newValue + '!');
3});
1// ...
2computed: {
3 fullName: {
4 // getter
5 get: () => {
6 return this.firstName + ' ' + this.lastName
7 },
8 // setter
9 set: (newValue) => {
10 var names = newValue.split(' ')
11 this.firstName = names[0]