同一page页面重复打开时,页面js里声明的变量会互相污染?

小程序 文章 2021-01-28 19:21 406 0 全屏看文

AI助手支持GPT4.0

同一page页面重复打开时,页面js里声明的变量会互相污染?When the same page is opened repeatedly, the variables declared in the page js will pollute each other?

同一page页面重复打开时,页面js里声明的变量会互相污染?

如下面代码片段中的that变量,在上面的页面关闭后,下面页面中that的指向变成了关闭了的页面.

这算是小程序的bug?还是就是目前这种规则?如果是已知规则,那官方是否需要改进一下?

https://developers.weixin.qq.com/s/mqa4fHme7ZnX

For example, the "that" variable in the following code fragment, after the top page is closed, the "that" point in the bottom page becomes the closed page. Is this a bug in a small program or the current rule? If it is a known rule, does the official need to improve it? https://developers.weixin.qq.com/s/mqa4fHme7ZnX

回答:

面条君:

你这代码里就只有一个页面。。。跳来跳去还是那个

治辰科技于鲁宁:实际应用中,很多这种应用场景.比如商城中的商品详情页面,或搜索页面.会被多次重复打开.
治辰科技于鲁宁:比如A商品页面里有个B商品链接,显示商品都用同一个page,在不关闭A商品页面的情况下,同时打开B商品页面.
拾忆:

一个页面的进10次栈 AppData 面板数据 都是一套 最新的

治辰科技于鲁宁:实际是每个栈中的变量是不冲突的.比如说页面data里的自定义变量等.否则不乱套了?!
brave:

看不太懂你要表达什么意思,或者你要做什么东西?

治辰科技于鲁宁:that指向this,js里就不用考虑this这个关键字在使用时的局限性.
治辰科技于鲁宁:在用this的地方,统一改用that即可

-EOF-

AI助手支持GPT4.0