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

小程序 文章 2021-03-22 18:21 536 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群

相关文章
小程序公众号已关联,用户未关注公众号,使用小程序的openid,公众号的模板消息,可以推消息吗?
往data的数组里添加object元素,偶尔会覆盖掉原来的数据?
小程序跳转H5 使用H5页面支付嘛?
参数?不知道怎么修改
流量主开通一个多月了(2021年2月20号开通),收入现在还末进入结算流程?
随便看看
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8031
问题? 7262
如何快速搭建抽奖助手小程序(无需代码知识) 5046
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6001
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5517
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5213
如何解决渲染层网络错误Failed to load media? 16563
小程序找号找回 释放昵称? 2426
我的小程序广告主收入5301,实际进账4406,是怎么回事呀? 2508
删除部分微信用户个人数据的通知,怎么删除? 5555