[英]Vue.js bind id to onclick function
I have a Vue template that loops through an array and creates a table. 我有一个Vue模板,它遍历数组并创建表。 Each item in the table also gets a button that I want to bind a click event to, passing in a token that will be used in the click function.
表中的每个项目还获得了一个我想将click事件绑定到的按钮,并传递了将在click函数中使用的令牌。
I got the following error when I tried passing in the token using interpolation: 当我尝试使用插值传递令牌时遇到以下错误:
onclick="getClickedResult({{result.reportToken}})":
Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead.
For example, instead of <div id="{{ val }}">, use <div :id="val">
I understand that I can bind the click function using v-on:click="setClickedResult()" or I can attach the token to the button using :id="val" but I am confused on how to combine these so that the token gets passed into the function correctly. 我知道我可以使用v-on:click =“ setClickedResult()”绑定click函数,也可以使用:id =“ val”将令牌附加到按钮,但是我对如何组合这些令牌感到困惑被正确地传递到函数中。
What about this: 那这个呢:
<div v-on:click="getClickedResult(result.reportToken)">Click me!</div>
Or with the @
shorthand: 或使用
@
简写:
<div @click="getClickedResult(result.reportToken)">Click me!</div>
You don't need interpolation ( {{ ... }}
) inside v-on
attributes. 您不需要在
v-on
属性内进行插值( {{ ... }}
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.