在使用毫秒级自定义倒计组件时,是否有可能导致小程序页面相应迟钝?

小程序 文章 2022-04-15 11:40 366 0 全屏看文

AI助手支持GPT4.0

在使用毫秒级自定义倒计组件时,是否有可能导致小程序页面相应迟钝?When using a millisecond-level custom countdown component, is it possible to cause the applet page to be sluggish?

在使用毫秒级自定义倒计组件时,是否有可能导致小程序页面相应迟钝?

https://www.douyin.com/discover?modal_id=7086659212339727620(暂时无法上传腾讯视频)

前部分为开发工具预览效果,卡顿基本不存在;但是真机和预览操作时,手机出现严重卡顿无法正常使用功能,望论坛里大佬能给予优化代码意见


https://www.douyin.com/discover?modal_id=7086659212339727620 (Tencent video cannot be uploaded temporarily) the first part is the preview effect of development tools, and Caton basically does not exist; However, during the real machine and preview operation, the mobile phone is seriously stuck and can not use the function normally. I hope the leaders in the forum can give advice on optimizing the code

回答:

_UniqueBurning7:
setCountDown: function () {        var thisPage = this        var Pause = thisPage.data.isPause                if (Pause == false) {            //刷新时间以及递减时间范围            let time = 1000;            let wPause = thisPage.data.wasPause            let test = thisPage.data.pingData[0].time            var Text = thisPage.data.showText            let {                listData            } = thisPage.data;                        // map里   v为当前数组操作的元素,i为当前元素在数组的坐标            //对数组进行拆包            let list = listData.map((v, i) => {                if (v.time < 0) {                    v.time = 0;                }                //对元素进行日期输出格式化                let formatTime = thisPage.getFormat(v.time);                v.time -= time;                                v.countDown = `${formatTime.mm}:${formatTime.ss}`;                //进行是否曾经暂停                console.log("经过暂停前" +this.data.wasPause)                if (wPause == true) {                    v.time = v.time + 1000;                    //可以赋值                    thisPage.setData({                        wasPausefalse                                            })                    console.log("first time to regoing!")                    console.log("经过暂停后" + this.data.wasPause)                }                console.log(test)                console.log(thisPage.data.pingData[0])                if (v.time < 0) {                                    thisPage.setData({                        test0,                        showText"交换攻防",                        isPausetrue                    })                    console.log(Pause)                    thisPage.showPopup()                }                return v;            });                        thisPage.setData({                listData: list            });            //setTimeout里  在第二个函数指定毫秒时后触发第一个函数的方法            //现在语句意思为 =》在time=1000毫秒时,执行setCountDown方法,实则为循环            setTimeout(thisPage.setCountDown, time);        }        if (Pause == true) {            return        }

    }

补充代码块,目前只用到了一个秒级,但还是很卡

夜小猫:

起码弄个代码片段

_UniqueBurning7:好的,已补充代码块

-EOF-

AI助手支持GPT4.0