- wxs格式化db.serverdate(),如何对数据库时间转换成字符串形式?
数据库中的时间用db.serverdate()获取的时间,当wxml中使用{{util.timeFormt(weibo.create_tiem)}},模拟器中显示NaN,如果wxml中使用{{util.timeFormt(create_tiem)}},js中var crate_time = weibo[0].create_time.toString();进行转换,那么所有信息显示的时间都是一样的。下图第一张图,直接格式化数据库时间,显示NaN,第二张图,在JS中把date对象转换成字符串,显示的时间是一样的。这个时间格式化如何解决? [图片][图片] 云函数代码: return await db.collection("weibo").add({ data: { create_time:db.serverDate(), // create_time:new Date(db.serverDate()).toLocaleDateString(), device:device } }) } wxml代码: <view class="detail-info"> <view class="time">{{util.timeFormat(weibo.create_time)}}</view> // 模拟器得到的时间是NaN <view class="time">{{util.timeFormat(create_time)}}</view> // 模拟器得到是时间如图二,显示的时间是一样的。 <view class="from">来自{{weibo.device}}</view> </view> JS代码: loadWeibos(){ const that = this; db.collection("weibo").limit(10).get().then(res => { // console.log(res); const weibo = res.data; console.log(weibo); var create_time = weibo[0].create_time.toString(); // 把对象转换成字符串 console.log(create_time); that.setData({ weibo:weibo, create_time:create_time }) }) }, 代码片段:https://developers.weixin.qq.com/s/XruBZhmh7CRC
2024-05-18 - 在使用chooseMedia时,模拟器出现了N张图片,并且图片内容也没有展示出来,这是什么问题?
在使用chooseMedia时,选择图片后,模拟器出现了N张图片,并且图片内容也没有展示出来,如图: [图片][图片] 代码: <view wx:for="{{tempImages}}" wx:key="item" class="image-group" style="width:{{imageSize}}px;height:{{imageSize}}px;"> <image src="{{item}}"></image> <view class="close-btn" bind:tap="onRmoveBtnTap" data-index="{{index}}"></view> </view> js代码: onAddImageTap(){ const that = this; wx.chooseMedia({ count:9, mediaType:['image'], sourceTypr:['album','camera'], success(res){ // console.log(res); const tempImages = res.tempFiles[0].tempFilePath; // const oldImages = that.data.tempImages; // const newImages = oldImages.concat(tempImages); that.setData({ // tempImages:newImages 注:如果使用注销的这段代码,在模拟器中可以正常展示,但是哪怕选择了4张图片, 只展示一张图片,需要一张一张的添加才能够正常展示 tempImages:tempImages }) } }) },
2024-05-11 - 使用chooseMedia,选择图片后就重复,也不展示图片内容,这是什么问题?
在使用chooseMedia时,选择图片后,模拟器出现了N张图片,并且图片内容也没有展示出来,如图: [图片][图片] 代码: <view wx:for="{{tempImages}}" wx:key="item" class="image-group" style="width:{{imageSize}}px;height:{{imageSize}}px;"> <image src="{{item}}"></image> <view class="close-btn" bind:tap="onRmoveBtnTap" data-index="{{index}}"></view> </view> js代码: onAddImageTap(){ const that = this; wx.chooseMedia({ count:9, mediaType:['image'], sourceTypr:['album','camera'], success(res){ // console.log(res); const tempImages = res.tempFiles[0].tempFilePath; // const oldImages = that.data.tempImages; // const newImages = oldImages.concat(tempImages); that.setData({ // tempImages:newImages 注:如果使用注销的这段代码,在模拟器中可以正常展示,但是哪怕选择了4张图片, 只展示一张图片,需要一张一张的添加才能够正常展示 tempImages:tempImages }) } }) },
2024-05-11 - chooseMedia选择图片重复展示,并报错,图片也不显示,怎么解决?
使用chooseMedia,选择图片后,展示N张图片,但是不显示图片内容,报错。如图: [图片][图片] 代码: <view wx:for="{{tempImages}}" wx:key="item" class="image-group" style="width:{{imageSize}}px;height:{{imageSize}}px;"> <image src="{{item}}"></image> 注:如果把item改成tempImages,就能够正常展示图片,但是不能解决如图重复问题,除非取消wx:for循环。 <view class="close-btn" bind:tap="onRmoveBtnTap" data-index="{{index}}"></view> </view> JS代码: onAddImageTap(){ const that = this; wx.chooseMedia({ success(res){ const tempImages = res.tempFiles[0].tempFilePath; // const oldImages = that.data.tempImages; // const newImages = oldImages.concat(tempImages); that.setData({ // tempImages:newImages 注:如果使用注销的代码,就能够正常展示,但是不管选择几张图片,只展示一张图片 tempImages:tempImages }) } }) },
2024-05-10 - 使用chooseMedia,选择图片后报错,并且重复上传了N张图片?
使用chooseMedia,选择一张图片之后,展示了无数张图片,并且没有显示出图片,如图: [图片] 报错如图: [图片] 代码: <view wx:for="{{tempImages}}" wx:key="item" class="image-group" style="width:{{imageSize}}px;height:{{imageSize}}px;"> <image src="{{item}}"></image> 注:如果把item改成tempImages就可以展示出图片,但是不能解决重复问题,除非取消wx:for循环 <view class="close-btn" bind:tap="onRmoveBtnTap" data-index="{{index}}"></view> </view> js代码: onAddImageTap(){ const that = this; wx.chooseMedia({ count:9, mediaType:['image'], sourceTypr:['album','camera'], success(res){ const tempImages = res.tempFiles[0].tempFilePath; // const oldImages = that.data.tempImages; // const newImages = oldImages.concat(tempImages); that.setData({ // tempImages:newImages 注:如写了注销的这段代码就能够正常展示,但是一次只能够选择一张图片, 哪怕选择了3张图片,展示的还是一张图片 tempImages:tempImages }) } }) },
2024-05-10 - 页面中globalData为null?
做了个登录页面,在页面中用globalData时为null,数据库里面有信心,每次刷新都要重新登录,这个问题怎么解决,求大师帮帮忙。 [图片][图片] me.js代码 const app = getApp(); // const db = wx.cloud.database(); Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(app.globalData.userInfo) this.setData({ userInfo:app.globalData.userInfo }) }, // 获取头像 getAvatar(event){ console.log(event.detail.avatarUrl);//临时头像路劲地址 let avatarUrl = event.detail.avatarUrl;//临时地址 let suffix = /\.[^\.]+$/.exec(avatarUrl)[0]; wx.cloud.uploadFile({ cloudPath: 'loginImages/' + new Date().getTime() + suffix, filePath:avatarUrl //上传到云端的路劲, }).then(res => { console.log(res.fileID); this.setData({ avatarUrl:res.fileID }) }) }, login(event){ console.log(event.detail.value.nickName); let nickName =event.detail.value.nickName; if(!nickName){ wx.showToast({ title:'请填写昵称', icon:'error' }) return } if(!this.data.avatarUrl){ wx.showToast({ title:'请上传头像', icon:'error' }) return } var that = this; console.log(app.globalData.openid); wx.cloud.database().collection('login_users').where({ _openid:app.globalData.openid }).get({ success(res){ console.log(res) if(res.data.length == 0){ //添加记录到数据库 wx.cloud.database().collection('login_users').add({ data:{ num:Date.now(),//!QQ号 avatarUrl:that.data.avatarUrl, nickName:nickName }, success(res){ console.log(res) wx.showToast({ title:'登陆成功', }) //设置userInfo这个对象 let userInfo = {}; userInfo.avatarUrl = that.data.avatarUrl; userInfo.nickName = nickName; that.setData({ userInfo }) // //第一次登录成功后获取最新用户信息 that.getUseInfo() } }) }else{ that.setData({ userInfo:res.data[0] }) } } }) }, loginOut(){ // console.log(event); app.globalData.userInfo = null this.setData({ userInfo:null }) }, //修改个人信息 editUserinfo(){ wx.navigateTo({ url:'edit/edit' }) }, /** * 生命周期函数--监听页面显示 */ onShow() { console.log(app.globalData.userInfo); this.setData({ userInfo:app.globalData.userInfo }) }, //获取用户信息 getUseInfo(){ let that = this; wx.cloud.database().collection('login_users').where({ _openid:app.globalData.openid }).get({ success(result){ console.log(result) app.globalData.userInfo = result.data[0] } }) } }) aapp.js代码 App({ onLaunch: function () { if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ env:'', traceUser: true, }); } //获取用户的openid var that = this; wx.cloud.callFunction({ name:'getOpenid', success(res){ console.log(res); that.globalData.openid = res.result.openid //查找数据库用户表里面是否有这个用户记录 wx.cloud.database().collection('login_users').where({ _openid:res.result.openid }).get({ success(result){ console.log(result) that.globalData.userInfo = result.data[0] } }) } }) }, globalData:{ userInfo:null, openid:null } });
2024-04-03 - 在做个登陆授权页面时报错 globalThis is not defined?
不管是打开官方授权的代码片段也好,还是怎么样,当点击头像或者昵称时就报这个错, globalThis is not defined,请问各位大师,这个怎么解决? [图片][图片]
2024-03-30 - 在pages页面设置的跳转id值传递,做成components组件,id值是空?
如图所示的布局,让所有列表跳转到一个页面,在pages页面中设置跳转正常,做成components组件时,显示id值为空,请问这个id值怎么传? [图片] [图片] 代码: components代码: <!--components/indextitle/indextitle.wxml--> <view class="title-list" > <navigator class="title-group" wx:for="{{items}}" wx:key="item" url="{{listUrl}}" data-index="{{index}}" > <image class="thumbnail" src="{{item.imgUrl}}" mode="" /> <text class="title">{{item.name}}</text> </navigator> </view> js代码 properties: { items:{ type:Object, value:{} }, listUrl:{ type:String, value:'' }, index:{ type:Array, value:[] } }, pages页面代码: <indextitle items="{{title}}" listUrl="/pages/list/list?id={{index}}"></indextitle> js代码: data: { title:[ {imgUrl:"../../images/automation.png",name:"自动化招聘"}, {imgUrl:"../../images/recruit-blue.png",name:"全职招聘"}, {imgUrl:"../../images/lin.png",name:"临时工招聘"}, {imgUrl:"../../images/part-tioe.png",name:"兼职招聘"}, {imgUrl:"../../images/graduates.png",name:"毕业生招聘"}, {imgUrl:"../../images/worker.png",name:"找工人"}, {imgUrl:"../../images/carpool-green.png",name:"拼车"}, {imgUrl:"../../images/invite.png",name:"邀请好友"}, ], },
2023-10-21 - pages页面传到components组件中,弹出传入的类型不兼容?
一直弹出警告,上传了一个代码片段,请帮忙改下 https://developers.weixin.qq.com/s/2uRiAVmp7mLW
2023-10-13 - 接受到的类型不兼容的值:应为<数字>,但得到的不是数字值。改为使用0。这样的警告怎么解决?
做了个星星的评分组件,但是一直就报出警告,如图中的两个警告怎么解决?如图: [图片] 代码如下: <!--components/stars/stars.wxml--> <view class="rate-group"> <image class="rate-image" style="width:{{starsize}}rpx;height:{{starsize}}" wx:for="{{lights}}" wx:key="key" src="../../images/rate-light.png" /> <image class="rate-image" style="width:{{starsize}}rpx;height:{{starsize}}" wx:for="{{hafls}}" wx:key="key" src="../../images/rate-half.png" /> <image class="rate-image" style="width:{{starsize}}rpx;height:{{starsize}}" wx:for="{{grays}}" wx:key="key" src="../../images/rate-gray.png" /> <text wx:if="{{istext}}" class="rate-text" style="font-size:{{fontsize}}rpx;color:{{fontcolor}}" >{{ratetext}}</text> </view> // components/stars/stars.ts properties: { rate: { type: Number, value: 0, observer(){ //newVal,oldVal,changedPath //属性被改变时执行的函数(可选),也可以写成在methods段中定义的方法名字符串,如:'_propertyChange' //通常newVal就是新设置的数据,oldVal是旧数据 this.updateRate(); } }, starsize: { type: Number, value: 20 //rpx }, fontsize: { type: Number, value: 20 //rpx }, fontcolor: { type: String, value: "#ccc" }, istext: { type: Boolean, value: true }, }, lifetimes: { attached: function () { this.updateRate() } }, methods: { updateRate:function(){ var that = this; // console.log(that.properties.rate); var rate = that.properties.rate; var intRate = parseInt((rate).toString()); var light = parseInt((intRate / 2).toString()); var hafl = intRate % 2; var gray = 5 - light - hafl; var lights = []; var hafls = []; var grays = []; for (var index = 1; index <= light; index++) { lights.push(index); } for (var index = 1; index <= hafl; index++) { hafls.push(index); } for (var index = 1; index <= gray; index++) { grays.push(index); } var ratetext = rate && rate > 0 ? rate.toFixed(1) : "未评分"; that.setData({ lights: lights, hafls: hafls, grays: grays, ratetext: ratetext }) } } <!--index.wxml--> <stars rate="{{item.rating.value}}"></stars>
2023-10-10