具体方法如下:
1.首先,在vue-cli中创建一个vue.js项目;
vue create project-name
2.vue.js项目创建好后,在项目中定义一个函数;
export default {data() {return {runOnce: true,};},methods: {func() {console.log('hello world', this);},};3.最后,函数定义好后,使用if语句即可设置函数只执行一次;
methods: {func() {console.log('hello world', this);},funcRunOnce() {if (this.runOnce) {this.func();this.runOnce = false;}},},
下一篇:vue怎么让标签隐藏