3π
β
The solution is to use computed values, b
will be accessible the same way as if it was declared in data
:
new Vue({
el: '#root',
data: {
a: 1
},
computed: {
// a computed getter
b: function() {
// `this` points to the vm instance
return this.a + 1
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
<div id="root">
{{ a }} and {{ b }}
</div>
π€WoJ
-1π
try this
var x;
new Vue(x = {
el: '#root',
data: {
a: 1,
b: () => x.data.a + 1
}
})
π€Semi-Friends
Source:stackexchange.com