- 时间格式化怎么显示NaN/NaN/NaNNaN/:NaN?
这个问题求解,图片如下 [图片] js代码: // pages/index/index.js Page({ /** * 页面的初始数据 */ data: { day:5 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { var time=new Date(2022,6,29,14,39,23).toLocaleString(); this.setData({ time:time }) }, wxml代码 <!--pages/index/index.wxml--> <wxs src="../utils/util.wxs" module="utils" /> <view>{{utils.timeFormat(time)}}</view> wxs代码 var timeFormat = function(time){ var date = getDate(time); var date_seconds = date.getTime() / 1000;//当前执行的秒数 var now = getDate(); var now_seconds = now.getTime() / 1000;//当前时间的秒数 var timestamp = now_seconds-date_seconds;//时间戳 var timeStr = "";//时间的字符串 if(timestamp<60){ timeStr = "刚刚"; }else if(timestamp >= 60 && timestamp < 60*60){ var minutes = parseInt(timestamp / 60); timeStr = minutes + "分钟前"; }else if(timestamp >= 60*60 && timestamp < 60*60*24){ var hours = parseInt(timestamp / 60 / 60 ); timeStr = hours + "小时前"; }else if(timestamp >= 60*60*24 && timestamp < 60*60*24*30){ var days = parseInt(timestamp/60/60/24); timeStr = days + "天前"; }else{ var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); timeStr = year+"/"+month+"/"+day+""+hour+":"+minute; } return timeStr; } module.exports={ timeFormat:timeFormat }
2022-07-29 - 时间格式化怎么显示[object object]?
[图片] 代码如下: // pages/index/index.js Page({ /** * 页面的初始数据 */ data: { day:5 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { var time=new Date(2022,6,29,11,0,0); console.log(time); this.setData({ time:time }) }, wxml <!--pages/index/index.wxml--> <view>{{time}}</view>
2022-07-29 - 把数据库的内容变成真实的数据,数据库有内容,但界面不显示数据内容?
[图片] [图片] 上面这个图显示不出内容出来,打印数据库有数据存在,另外就时间怎么显示是NaN?求各位大神帮忙解决下。代码如下: <!--index.wxml--> <wxs src="../../utils/util.wxs" module="util"/> <view class="container"> <view class="weibo-group" wx:for="{{weibos}}" wx:key="weibos" wx:for-item="{{weibo}}"> <view class="user-group"> <image class="avatar" src="{{weibo.author.avatarUrl}}"></image> <view class="right-info"> <view class="username">{{weibo.author.nickName}}</view> <view class="detail-info"> <view class="time">{{util.timeFormat(weibo.cretae_time)}}</view> <view class="from">来自{{weibo.device}}</view> </view> </view> </view> <view class="weibo-content-group"> <view class="content">{{weibo.content}}</view> <block wx:if="{{weibo.images.length > 0}}"> <!--1张图片的情况--> <view wx:if="{{weibo.images.length === 1}}" class="image-list-group"> <image src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/yingshiji.png" mode="aspectFill" style="width:100%;max-height:400rpx;" /> </view> <!--2张和4张图片的情况--> <view wx:elif="{{weibo.images.length === 2 || weibo.images.length === 4}}" class="image-list-group"> <image wx:for="{{weibo.images}}" wx:key="key" wx:for-item="image" src="{{image}}" mode="aspectFill" style="width:{{twoImageSize}}px;height:{{twoImageSize}}px;" /> </view> <!--3张图片的情况--> <view wx:else class="image-list-group"> <image wx:for="{{weibo.images}}" wx:key="key" wx:for-item="image" src="{{image}}" mode="aspectFill" style="width:{{threeImageSize}}px;height:{{threeImageSize}}px;" /> </view> </block> <!--视频的情况--> <block wx:if="{{weibo.video}}"> <view class="image-list-group"> <video src="{{weibo.video}}"></video> </view> </block> </view> <view class="weibo-handle"> <view class="comment-group"> <image src="../../images/comment.png" />评论 </view> <view class="praise-group"> <image src="../../images/praise.png" />赞 </view> </view> </view> <!--2张和4张图片的情况--> <!--<view class="weibo-group"> <view class="user-group"> <image class="avatar" src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/1.jpg"></image> <view class="right-info"> <view class="username">forry1</view> <view class="detail-info"> <view class="time">2019/1/1 11:11:11</view> <view class="from">来自iphone XR</view> </view> </view> </view> <view class="weibo-content-group"> <view class="content">大家快来学习小程序开发</view> <view class="image-list-group"> <image src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/yingshiji.png" mode="aspectFill" style="width:{{twoImageSize}}px;height:{{twoImageSize}}px;" /> <image src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/yingshiji.png" mode="aspectFill" style="width:{{twoImageSize}}px;height:{{twoImageSize}}px;" /> <image src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/yingshiji.png" mode="aspectFill" style="width:{{twoImageSize}}px;height:{{twoImageSize}}px;" /> <image src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/yingshiji.png" mode="aspectFill" style="width:{{twoImageSize}}px;height:{{twoImageSize}}px;" /> </view> </view> <view class="weibo-handle"> <view class="comment-group"> <image src="../../images/comment.png" />评论 </view> <view class="praise-group"> <image src="../../images/praise.png" />赞 </view> </view> </view>--> <!--3张图片的情况--> <!--<view class="weibo-group"> <view class="user-group"> <image class="avatar" src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/1.jpg"></image> <view class="right-info"> <view class="username">forry1</view> <view class="detail-info"> <view class="time">2019/1/1 11:11:11</view> <view class="from">来自iphone XR</view> </view> </view> </view> <view class="weibo-content-group"> <view class="content">大家快来学习小程序开发</view> <view class="image-list-group"> <image wx:for="{{images}}" wx:key="key" src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/yingshiji.png" mode="aspectFill" style="width:{{threeImageSize}}px;height:{{threeImageSize}}px;" /> <view wx:if="{{images.length%3 == 2}}" style="width:{{threeImageSize}}px;height:{{threeImageSize}}px;"></view> </view> </view> <view class="weibo-handle"> <view class="comment-group"> <image src="../../images/comment.png" />评论 </view> <view class="praise-group"> <image src="../../images/praise.png" />赞 </view> </view> </view>--> <!--视频的情况--> <!-- <view class="weibo-group"> <view class="user-group"> <image class="avatar" src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/1.jpg"></image> <view class="right-info"> <view class="username">forry1</view> <view class="detail-info"> <view class="time">2019/1/1 11:11:11</view> <view class="from">来自iphone XR</view> </view> </view> </view> <view class="weibo-content-group"> <view class="content">大家快来学习小程序开发</view> <view class="image-list-group"> <video src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/video/汽车视频.mp4"></video> </view> </view> <view class="weibo-handle"> <view class="comment-group"> <image src="../../images/comment.png" />评论 </view> <view class="praise-group"> <image src="../../images/praise.png" />赞 </view> </view> </view>--> </view> <view class="write-weibo-btn" bind:tap="onWriteWeiboTap"> <view>+</view> </view> index.js代码如下: //index.js const app=getApp() const db = wx.cloud.database() Page({ /** * 页面的初始数据 */ data: { images:[1,2,3,4,5,6,7,8,9] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.initImageSize() this.loadWeibos() // this.onWriteWeiboTap() }, loadWeibos:function(){ const that = this; db.collection("weibo").limit(10).get().then(res=>{ // console.log(res); const weibos = res.data; console.log(weibos); that.setData({ weibos:weibos }) }) }, 时间代码如下: // var weekdays = [ // '星期一', // '星期二', // '星期三', // '星期四', // '星期五', // '星期六', // '星期天' // ] // a=10; // console.log(a); var timeFormat = function(time){ var date = getDate(time); var date_seconds = date.getTime() / 1000; var now = getDate(); var now_seconds = now.getTime() / 1000; var timestamp = now_seconds - date_seconds; var timeStr = ""; if(timestamp < 60){ timeStr = "刚刚"; }else if(timestamp >= 60 && timestamp < 60 * 60){ var minutes = parseInt(timestamp / 60); timeStr = minutes + "分钟前"; }else if(timestamp >= 60 * 60 && timestamp < 60 * 60 * 24){ var hours = parseInt(timestamp / 60 / 60); timeStr = hours + "小时前"; }else if(timestamp >= 60 * 60 * 24 && timestamp < 60 * 60 * 24 * 30){ var days = parseInt(timestamp / 60 / 60 / 24); timeStr = days + "天前"; }else{ var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); timeStr = year + "/" + month + "/" + day + " " + hour + ":" + minute; } return timeStr; } module.exports={ timeFormat:timeFormat, // weekdays:weekdays }
2022-07-28 - 云存储路径怎么是undefind?
[图片] [图片] 这路径日期后面显示undefined,求解,这是什么问题? 代码如下: //上传图片到云服务器 const fileIDList=[]; if(that.data.tempImages.length > 0){ const today = new Date(); const year = today.getFullYear(); const month = today.getMonth() +1; const day = today.getDate(); that.data.tempImages.forEach((value,index) => { const cloudPath = "weibos/"+year+"/"+month+"/"+day+"/"+getUUID()+"/"+"."+getExt(value); wx.cloud.uploadFile({ filePath:value, cloudPath:cloudPath, success:res=>{ console.log(res); // fileIDList.push(res.fileID); // if(fileIDList.lenght == that.data.tempImages.lenght){ // //接下来就是发布微博了 // wx.hideLoading({}); // wx.showToast({ // title:"图片都上传完成" // }) // } } }) }) } },
2022-07-26 - 每次更改pages下的文件index中content中内容,就要重新部署云函数,否则就报错?
每次更改pages下的文件index中content中内容,就要重新部署云函数,否则就报错? [图片] // 云函数入口函数 exports.main = async (event, context) => { const content = event.content; const tokenResponse = await got(tokenUrl); const access_token = JSON.parse(tokenResponse.body).access_token; checkUrl = checkurl+access-token; const checkResponse = await got.post(checkUrl,{ body:JSON.stringify({ content:content }) }) return checkResponse.body } // 文字内容安全监测 wx.cloud.callFunction({ name:"msgCheck", data:{ content:"特3456书yuuo莞6543李zxcz蒜7782法fgnv级" }, success:res =>{ console.log(res); }, fail:err => { console.error(err); } })
2022-07-21