目前有没有小伙伴在做,uniapp+vue开发安卓app,遇到定时器开发完成之后手机上不计时的问题

如果目前也有用uniapp+vue开发安卓app的伙伴,也可以联系,多交流,毕竟这里面好多坑

怎么解决,浏览器上都运行好了,到了手机上不行

问题已解决,整个流程看上一篇文章

上一篇文章中在储存的时候用的本地,打包apk都手机上有些问题,真机测试发现是储存问题,那么咱们就不偷懒了,改到store里面去

基本的时间储存以及修改,提取,删除函数

store文件中

在我们的计时器页面

startpro() {
                console.log('时间hanshu')
                // if (localStorage.getItem('firsttime') === null) {
                //     localStorage.setItem('firsttime', new Date());
                // } else {

                // }
                // 从 Vuex store 获取 firstTime
                const firstTime = this.$store.getters.getFirstTime;
                console.log(firstTime); // 输出第一次访问的时间

                if (firstTime == null) {
                    // 设置 firstTime 到 store
                    this.$store.commit('setFirstTime', new Date());
                }
                this.intervalId = setInterval(() => {
                    this.elapsedSeconds++;
                    // this.$set(this, 'elapsedSeconds', this.elapsedSeconds);
                    console.log(this.elapsedSeconds, '时间观看')
                    console.log(firstTime); // 输出第一次访问的时间


                }, 1000);}

开始函数部分,将注释的那种方法改成下面使用的那种

    stoppro() {
                console.log('取消巡检')
                clearInterval(this.intervalId);
                // localStorage.setItem('firsttime', 'empt');
                // localStorage.removeItem('firsttime');
                this.$store.commit('clearFirstTime');}

清楚函数里面也改

onLoad(option) {
            let that = this
            console.log("1111111", this.taskId);
            this.taskId = option.id
            this.getData()

            const isvalue = this.$store.getters.getFirstTime;
            console.log(isvalue, 'store.getters.getFirstTime');

            if (isvalue === null) {
                console.log("直接调用的")
                this.startpro()


            } else if (isvalue) {
                console.log('进入了第二遍的函数')
                const nowtime = new Date()


                const timeDifference = nowtime - new Date(isvalue)
                this.elapsedSeconds = Math.floor(timeDifference / 1000);
                console.log(this.elapsedSeconds, 'this.elapsedSeconds')
                this.startpro()
            }

        },

触发位置也改掉,就这三个涉及到的地方,储存方式改了就没问题了

(整个流程看上一篇,我就不再写一遍了)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值