computed properties code example
Example 1: computed setter
computed: {
fullName: {
get: function () {
return this.firstName + ' ' + this.lastName
},
set: function (newValue) {
var names = newValue.split(' ')
this.firstName = names[0]
this.lastName = names[names.length - 1]
}
}
}
Example 2: js computed style
window.getComputedStyle(document.getElementById("11")).width
Example 3: vue computed
var vm = new Vue({
el: '#example',
data: {
message: 'Hello'
},
computed: {
reversedMessage: function () {
return this.message.split('').reverse().join('')
}
}
})
Example 4: computed property in javascript
let propertyname = 'c';
let obj ={
a : 11,
b : 12,
[propertyname] : 13
};
obj;
let a_value = {
[obj.a] = obj
};