有什么方法可以从参数中传递函数名吗?
像这样的事情..
<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/