如何在Vue Js中将动态函数名称传递给click事件 [英] How to pass a dynamic function name to the click event in Vue Js
本文介绍了如何在Vue Js中将动态函数名称传递给click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以通过参数传递函数名吗?
Is there any way we can pass the function name from the parameters ?
类似这样的东西.
<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在呈现页面时未转换为相应的功能. 什么是正确的方法,任何建议将不胜感激?
item.click is not converting as corresponding function while rendering the page. what is the correct approach any suggestions will be appreciated ?
推荐答案
要使用动态函数调用,建议使用帮助函数来接收函数名称并调用相应的函数.
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]()
},
从模板上遍历项目时,可以通过传递函数名称(如
And from template when iterating over items you can call that function by passing the function name like
<button v-for="button of items"
:key="button.id"
@click="handle_function_call(button.fn_name)" //=> note here
>
{{ button.text }}
</button>
在运行中查看它在jsfiddle中
这篇关于如何在Vue Js中将动态函数名称传递给click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文