computed
-
Type:
Object
-
Details:
Computed properties to be mixed into the Vue instance. All getters and setters have their
this
context automatically bound to the Vue instance. -
Example:
12345678910111213141516171819202122var
vm =
new
Vue({
data: { a: 1 },
computed: {
// get only, just need a function
aDouble:
function
() {
return
this
.a * 2
},
// both get and set
aPlus: {
get:
function
() {
return
this
.a + 1
},
set:
function
(v) {
this
.a = v - 1
}
}
}
})
vm.aPlus
// -> 2
vm.aPlus = 3
vm.a
// -> 2
vm.aDouble
// -> 4
-
See also:
Please login to continue.