6). Vue.js Computed block and normal method
computed property use to make complex logic put in to computed block.
The difference is that computed properties are cached based on their dependencies. A computed property will only re-evaluate when some of its dependencies have changed.
The difference is that computed properties are cached based on their dependencies. A computed property will only re-evaluate when some of its dependencies have changed.
Normal method invocation will always run the function whenever a we call.
<template>
<div id="app">
<template>
<div id="app">
<div class="container">
<button v-on:click="counter++" class="btn btn-success">Increment</button>
<button v-on:click="counter--" class="btn btn-danger">Decrement</button>
<button v-on:click="taskDone" class="btn btn-info">Completed</button>
<hr/>
<p>{{ view }}</p>
</div>
</div>
</div>
</template>
<script>
export default
{
data :{
counter: 0
},
computed: {
view: function () {
return this.counter < 0 ? 0 : this.counter;
}
},
method:{
taskDone: function(){
alert("Task Completed");
}
}
</script>
Comments
Post a Comment