简体   繁体   English

Vue.js- 调用函数并使用 v-on:click 运行表达式

[英]Vue.js- Calling a function AND running an expression with v-on:click

This answer shows how to call two functions with v-on by doing v-on:click="firstFunction(); secondFunction();"这个答案显示了如何通过执行v-on:click="firstFunction(); secondFunction();"使用v-on调用两个函数. . But in my project, I need to call a function besides an expression imposed by Vuetify .但是在我的项目中,除了Vuetify强加的表达式之外,我还需要调用一个函数。 The default Vuetify code is:默认的Vuetify代码是:

<v-btn color="success" @click="dialog = false">
  Save Row
</v-btn>

However beside the expression dialog = false, I need to call a certain function newRow() .但是,除了表达式 dialog = false 之外,我还需要调用某个函数newRow() I tried:我试过:

 <v-btn color="success" @click="newRow(); dialog = false">
    Save Row
</v-btn>

But that breaks the Vuetify functionality (the dialog doesn't close anymore).但这破坏了Vuetify功能(对话框不再关闭)。 Any suggestion?有什么建议吗?

Inside your newRow() method add :newRow()方法中添加:

      methods:{
          newRow(){
           //here put the logic to add new row 
           //and after that close the dialog box
           this.dialog=false;
           }
      ...
     }

and call it in the template like :并在模板中调用它,如:

  <v-btn color="success" @click="newRow()">
    Save Row
  </v-btn>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM