vue.js - 如何将动态函数名称传递给 Vue Js 中的点击事件

标签 vue.js dynamicform

有什么方法可以从参数中传递函数名吗?

像这样的事情..

<tr v-for="item in items" class="static" 
    v-bind:class="{'evenRow': item.oddeven=='1', 'oddRow': item.oddeven=='0' }"
@click="item.click(item.contactID)" >

</tr>  

item.click 在呈现页面时未转换为相应的函数。 什么是正确的方法,我们将不胜感激?

最佳答案

To use dynamic function call it is suggested to have a helper function that receives the function name and call the corresponding function.

handle_function_call(function_name) {
    this[function_name]()
},

并且在迭代项目时从模板中您可以通过传递函数名称来调用该函数

<button v-for="button of items"
       :key="button.id" 
       @click="handle_function_call(button.fn_name)" //=> note here
>
  {{ button.text }}
</button>

See it in action in jsfiddle

关于vue.js - 如何将动态函数名称传递给 Vue Js 中的点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52811581/

相关文章:

vue.js - 测试套件无法运行在 vue3 中使用 jest 时找不到模块 'vue-template-compiler

javascript - 在 vue.js SFC 中使用 lodash.throttle 超时的数据值

reactjs - Formik - 在 API 调用后更新初始值

YII2 添加 whenClient 到动态表单

vue.js - 如何在 vuetify 上添加 google recaptcha 3?

javascript - Vue 警告我无法在未定义、空或原始值 : null 上设置 react 属性

javascript - 在 vue 中保存预填充的输入

javascript - AngularJS Controller 返回表单

javascript - wbraganca yii2 动态表单日期选择器问题?

javascript - 使用 Pug (Jade) 和 JavaScript 的动态表单