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

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