Ton*_*Tom 5 dynamicform vue.js
有什么方法可以通过参数传递函数名称?
像这样的东西..
<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>
Run Code Online (Sandbox Code Playgroud)
item.click在呈现页面时未转换为相应的功能。什么是正确的方法,任何建议将不胜感激?
要使用动态函数调用,建议具有一个辅助函数,该辅助函数接收函数名称并调用相应的函数。
handle_function_call(function_name) {
this[function_name]()
},
Run Code Online (Sandbox Code Playgroud)
从模板上遍历项目时,您可以通过传递函数名称来调用该函数,例如
<button v-for="button of items"
:key="button.id"
@click="handle_function_call(button.fn_name)" //=> note here
>
{{ button.text }}
</button>
Run Code Online (Sandbox Code Playgroud)
在jsfiddle中查看实际效果
| 归档时间: |
|
| 查看次数: |
2690 次 |
| 最近记录: |