Vue.js 绑定id到onclick函数
Vue.js bind id to onclick function
我有一个循环遍历数组并创建 table 的 Vue 模板。 table 中的每个项目还获得一个按钮,我想将其绑定到点击事件,并传入将在点击功能中使用的令牌。
当我尝试使用插值传递令牌时出现以下错误:
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">
我知道我可以使用 v-on:click="setClickedResult()" 绑定点击功能,或者我可以使用 :id="val" 将令牌附加到按钮,但我对如何操作感到困惑将它们结合起来,以便令牌正确传递到函数中。
这个怎么样:
<div v-on:click="getClickedResult(result.reportToken)">Click me!</div>
或 @
shorthand:
<div @click="getClickedResult(result.reportToken)">Click me!</div>
您不需要在 v-on
属性内进行插值 ({{ ... }}
)。
我有一个循环遍历数组并创建 table 的 Vue 模板。 table 中的每个项目还获得一个按钮,我想将其绑定到点击事件,并传入将在点击功能中使用的令牌。
当我尝试使用插值传递令牌时出现以下错误:
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">
我知道我可以使用 v-on:click="setClickedResult()" 绑定点击功能,或者我可以使用 :id="val" 将令牌附加到按钮,但我对如何操作感到困惑将它们结合起来,以便令牌正确传递到函数中。
这个怎么样:
<div v-on:click="getClickedResult(result.reportToken)">Click me!</div>
或 @
shorthand:
<div @click="getClickedResult(result.reportToken)">Click me!</div>
您不需要在 v-on
属性内进行插值 ({{ ... }}
)。