I have defined a variable with the name tn which has number 10. I am trying to pass tn (which has 10) in the v-on:click="add(tn)" but it does not work. Is it something I am missing.
<script>
var tn = 10;
</script>
<div id="vue-app">
<p>My age is {{age}}</p>
<button v-on:click="add(1)"> Add a Year</button>
<button v-on:click="subtract(1)"> Subtract a Year</button>
<button v-on:click="add(tn)"> Add a Year</button>
<button v-on:click="subtract(tn)"> Subtract a Year</button>
</div>
<script>
new Vue({
el: '#vue-app',
data: {
age: 25
},
methods: {
add: function (inc) {
this.age += inc;
},
subtract: function (dec) {
this.age -= dec;
}
}
})
</script>
with(this) {}block around your template (see here). so if you writetnin your template, it will be interpreted asthis.tn, same withwindow, which will becomethis.window