this is the normal javascript code for calling onclick event only once:
JavaScript
x
9
1
<button onclick="myFunction(); this.onclick=null;">This button works only once</button>
2
<button onclick="myFunction()">This button works always</button>
3
<script>
4
function myFunction() {
5
console.log("hello");
6
}
7
</script>
8
</body>
9
the trick for normal javascript is this:
JavaScript
1
2
1
<button onclick="myFunction(); this.onclick=null;">
2
But, now I want this functionality in vue.js and my button in vue.js is like following:
JavaScript
1
7
1
<input
2
type="submit"
3
value="Start"
4
name="start_button"
5
@click="start"
6
/>
7
Can anyone suggest me how to call event exactly once in vuejs….
Advertisement
Answer
Use the .once
event modifier to handle the event only once:
JavaScript
1
2
1
<input @click.once="start">
2