如何阻止一个事件运行一次执行两次?

小程序 文章 2021-03-22 18:21 650 0 全屏看文

AI助手支持GPT4.0

如何阻止一个事件运行一次执行两次?How to prevent an event from running once and executing twice?

如何阻止一个事件运行一次执行两次?

如下图框选的地方是一个组件,通过判断点击tab的下标来判断,点击了最新还是最热

就涉及一个传值的问题,传值代码如下:

通过组件传值给调用页面,发现调用页面,在初始化加载的过程中也执行了bind:tabindex="clickTab"该事件

现在是如下图所示,该事件执行了两次:

commload,是加载评论的事件,然后我进入页面也调用了该事件

通过打印一进入页面就执行两次,测试是该组件传值得到,请问有会的大神有解决方案吗?

As shown in the figure below, the selected place is a component, which can be judged by clicking the subscript of tab. If you click the latest or the hottest, it will involve the problem of value transfer. The value transfer code is as follows: pass the value to the calling page through the component, and find that the calling page is executed during the initial loading process bind:tabindex= "Clicktab" indicates the event Now, as shown in the figure below, this event has been executed twice: commload, which is the event of loading comments. Then I also called this event when I entered the page, and it was executed twice as soon as I entered the page by printing. The test was obtained by passing the value of this component. Do you have a solution?

回答:

国民校草:

可以看小程序组件生命周期等api

铅笔画不出蜡笔的味道:

首先应该去找执行两次的原因,再不行就用全局变量控制

没有然后:

上复现问题的代码片段吧,你这样截图很难猜出来哪里的问题

奕K:通过组件传值给调用页面,发现调用页面,在初始化加载的过程中也执行了bind:tabindex="clickTab"该事件
奕K:不用猜的,我现在发现的问题就是该组件执行了此事件一次评论,然后我进入页面也加载了一次评论

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
自定义导航栏的情况下,如何控制web-view?
同一小程序,同一用户,openid不同
开放社区小程序版从个人主页关注入口查看关注人,无法点开关注人详情信息页打开后显示空白
刚买到的域名,就被微信拦截了?
图中⭕ 的客服是官方的,还是自己的?
随便看看
BT面板查看网站入口、账号密码的命令 6009
ucloud海外服务器超级优惠券 3274
根据您的消费情况,您的延停权益已发生变化,变更后的延停权益为延停额度20.00元 5831
为什么我们喜欢迈克尔杰克逊。 4164
阿里云com、cn域名续费优惠码(2020年5月可用) 3586
阿里云com、cn域名续费优惠码(2020年6月可用) 3606
微信公众号开五联增值税发票怎么处理 2950
仙之侠道幻彩衣的合成和属性预览 4316
仙之侠道2.8四象玉的合成和图片属性预览 3945
仙之侠道2.8赤狱战甲合成和属性预览 3266