html52.com
我爱小程序-开发者交流社区

如图,写的倒计时组件里this.setData无法正常赋值?

setCountDown: function () {
        var thisPage = this
        let 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;


                if (test <= 0) {                    
                   thisPage.setData({
                        test0,
                        Text : "交换攻防",
                        Pause : true,                        
                    })
                    console.log(Text)
                    thisPage.showPopup()
                }
                v.countDown = `${formatTime.mm}:${formatTime.ss}`;
                console.log("经过暂停前" + wPause)
                if (wPause == true) {
                    v.time = v.time + 1000;
                    thisPage.setData({
                        wasPausefalse
                    })
                    console.log("first time to regoing!")
                    console.log("经过暂停后" + wPause)
                }


                console.log(test)
                console.log(thisPage.data.pingData[0])


                return v;
            })
            thisPage.setData({
                listData: list
            });
            //setTimeout里  在第二个函数指定毫秒时后触发第一个函数的方法
            //现在语句意思为 =》在time=1000毫秒时,执行setCountDown方法,实则为循环
            setTimeout(thisPage.setCountDown, time);
        }
        if (Pause == true) {
            return
        }

写的自定义倒计时组件里,this.setData一直不能给页面data数据赋值。源代码在片段中调试可行,移植后出现问题

网友回复

记不起:

这种情况看看是否是有冲突,导致没有赋值成功

武曲心:

数组的变量换成深拷贝试试

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付