0👍
There would many ways yo achieve your goal but if you want out of vue instance You need to assign vue instance in a variable like below
var app = new Vue({
And then change counter
as app.counter
var app = new Vue({
el: '#app',
data: {
counter: 1
},
template: `<div id="el1" :data-val="counter">
<div>Value: {{ getCounter }}</div>
<div><input type="text" v-model="counter"></div>
</div>`,
computed: {
getCounter: function(val, oldVal){
return this.callMethod1(this.counter);
}
},
methods:{
callMethod1: function(){
console.log("callMethod1 called with counter value : "+this.counter);
return this.counter;
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app"></div>
Source:stackexchange.com