首页 > 解决方案 > 如何在 vue @click 事件中传递 Boolean:true?

问题描述

@click.native="scrollTo(index,true)"

我的期望:总是传递Boolean:true给函数 scrollTo Vue 的反应:Vue 将true其视为变量的名称,因此在 scrollTo 函数中,我得到了Number:indexandundefined

如何解决?

标签: javascriptvue.js

解决方案


my mistake.... I forgot there was another event @touchstart="scrollTo(index)" ahead of @click.native="scrollTo(index,true)" that's why I got undefined in scrollTo function.

Yes. vue can pass Boolean:true into function


推荐阅读