微信小程序console.log(time)打印出三行时间,赋值给data,却显示一条数据求大神指点

微信小程序console.log(time)打印出三行时间,赋值给data,却显示一条数据求大神指点,第1张

这是因为 setData 方法只能设置一个值,而你在 console.log 中打印了多行。

如果要在 pageData 中显示多行数据,可以将其更改为一个数组,并段谈孝在循环握稿中将每个时间侍友推入数组中。例如:

 let times = [] 

// 循环中 

let d = new Date(item.time.replace(/-/g, '/')).getTime()

let time = timeHandle(d)

times.push(time) 

// 循环结束后 

this.setData({ 

pageData:times 

})

如果你要显示最新的时间那么可以在循环结束后使用unshift方法添加到数组的第一个位置

<view class="mygroupForm-yzm {{isClicked?'mygroupForm-active':''}}" bindtap="{{isClicked?'':'timeClcik'}}">{{ytext}}</view>

const util = require('../../utils/util.js')

timeClcik(){

    let _this=this

    if (!_this.data.isClicked) {

      wx.showToast({

      title: '验证码已发迹辩送',

      })

      /锋凯/开始倒计时60秒

      setTimeout(()=>{

        _this.setData({

          isClicked:true

        })

     银州唤   util.settime(_this,60)

      },1500)

     }

  },

function settime(_this,count){

  if (count == 0) {

    _this.setData({

      ytext: '获取验证码',

      isClicked:false

    })

    return

  }

  _this.setData({

    isClicked:true,

    ytext: count + '秒后重发',

  })

  setTimeout(function(){

    count--

    settime(_this, count)

  }, 1000)

}

module.exports = {

  settime: settime

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12452658.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存