微信小程序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方法添加到数组的第一个位置

多次拒绝登录和允许登录

微信小程序的登录获取用户信息,是通过微信d出窗口,用户可点击允许 和拒绝两个按钮,点击允许,则获取用户信息登录成功,若点击拒绝,闭毕则获取失败,可通过二次请轿掘芹求调散渗用d起获取用户信息窗口。

具体代码如下:

//app.js

App({

onLaunch: function () {

//调用API从本地缓存中获取数据

var logs = wx.getStorageSync('logs') || []

logs.unshift(Date.now())

wx.setStorageSync('logs', logs)

console.log('logs',logs)

},

getUserInfo:function(cb){

var that = this

//调用登录接口

function getOpenid(backMsg){

that.globalData.userInfo = backMsg.userInfo

that.globalData.encryptedData = backMsg.encryptedData

that.globalData.iv = backMsg.iv

that.globalData.login = true

console.log(that.globalData.code)

wx.request({

url:that.localUrl+'Login/sendCodeLogin',

data:{

code:that.globalData.code,

encryptedData: backMsg.encryptedData,

iv:backMsg.iv

},

success:function(openData){

console.log('返回openid',openData,openData.data)

if(openData.data.code==1001){

that.globalData.openid = openData.data.data.openid

wx.setStorageSync('openid',that.globalData.openid)

wx.setStorageSync('userInfo',that.globalData.userInfo)

wx.setStorageSync('isManager', openData.data.data.isManager)

wx.showToast({

title: '登录成功',

icon: 'success',

duration: 500

})

typeof cb == "function" &&cb(that.globalData.userInfo)

}else{

wx.showLoading({

title: '登录失败'

})

setTimeout(function () {

wx.hideLoading()

}, 500)

}

}

})

}

wx.login({

success: function (msg) {

console.log('code',msg)

if(msg.code){

that.globalData.code = msg.code

if(that.globalData.login==false){

wx.openSetting({

success: function (data) {

if(data) {

if (data.authSetting["scope.userInfo"] == true) {

//loginStatus = true

wx.getUserInfo({

withCredentials: false,

success: function (res) {

console.log('第二次成功',res)

getOpenid(res)

},

fail: function (res) {

that.globalData.login = false

console.log('二次失败',res)

}

})

}else{

that.globalData.login = false

console.log('二次失败02')

}

}

},

fail: function () {

console.info("设置失败返回数据")

}

})

}else{

wx.getUserInfo({

success: function (res) {

console.log('第一次成功',res)

getOpenid(res)

},fail:function(msg){

that.globalData.login = false

console.log('第一次失败',msg)

}

})

}

}

},

fail:function(res){

console.log(res)

}

})

},

globalData:{

userInfo:null,

encryptedData:null,

iv:null,

openid:null,

code:null

}

})


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存