The method of making a function execute only once in vue
This article mainly explains "the method of letting the function be executed only once in vue". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the method of making 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
After the 2.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, you can use the if statement to set the function to be executed only once
Methods: {func () {console.log ('hello world', this);}, funcRunOnce () {if (this.runOnce) {this.func (); this.runOnce = false;}},}, now that you have a better understanding of "the method of making the function execute only once in vue", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!