How to make the function execute only once in vue
This article mainly explains "how to make the function execute only once in vue", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to make the function execute only once in vue"!
The specific methods are as follows:
1. First, create a vue.js project in vue-cli;
vue create project-name
2.After the vue.js project is created, define a function in the project;
export default {data() {return {runOnce: true,};},methods: {func() {console.log('hello world', this);},};
3. Finally, after the function is defined, use the if statement to set the function to execute only once;
methods: {func() {console.log ('hello world', this);},funcRunOnce() {if (this.runOnce) {this.func();this.runOnce = false;}},}, at this point, I believe that everyone has a deeper understanding of "how to make the function execute only once in vue", you may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!