- 下拉刷新,真机上下拉后不回弹,上拉加载,切换页面一直显示加载中?
下拉刷新如图,模拟器正常,真机上不回弹。上拉加载,切换到其他页面时,如果没有数据或者上拉的动作,就一直显示加载中,这问题怎么解决,求助大佬 [图片][图片] wxml代码 <view class="carpool-title"> <text class="title-text">百姓同城拼车网-同城拼车</text> </view> <view class="ad-group"> <image class="ad-image" src="../../images/专注.jpg" mode="" /> </view> <view class="search-input-group"> <view class="input-group"> <input class="search-input" placeholder="出发地" /> <image class="thumbnail" src="../../images/return.png" mode="" /> <input class="search-input" placeholder="终点" /> </view> <button class="search-button" size="mini">查询</button> </view> <segment-carpool items="{{items}}" wehicle="{{wehicle}}" binditemchengde="onItemChengdeEvent" defaultIndex="0"> <view slot="0" class="segment-page wehicle-page"> <wehicle wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="1" class="segment-page people-page"> <wehicle wx:if="{{wehicle.carpool == '我要找车'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="2" class="segment-page train-page"> <wehicle wx:if="{{wehicle.carpool == '我要找人'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="3" class="segment-page money-page"> <wehicle wx:if="{{wehicle.carpool == '我找货车'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="4" class="segment-page money-page"> <wehicle wx:if="{{wehicle.carpool == '我要找货'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> </segment-carpool> <loadingmore hasmore="{{hasmore}}"></loadingmore> JS代码 const db = wx.cloud.database(); Page({ data: { items:["全部","我要找车","我要找人","我找货车","我要找货"], hasmore:true, wehicles:[], }, onLoad(options) { }, onItemChengdeEvent(event){ }, lowdrelease(start=0){ const that = this; let promise = db.collection("wehicle"); if(start>0){ promise = promise.skip(start); } promise.limit(10).orderBy("create_time", "desc").get().then(res => { const wehicles = res.data; let hasmore = true; if(wehicles.length == 0){ hasmore = false } let newWehicles = []; if(start > 0){ newWehicles = that.data.wehicles.concat(wehicles); }else{ newWehicles = wehicles; } that.setData({ wehicles:newWehicles, hasmore:hasmore }) }) }, /** * 生命周期函数--监听页面显示 */ onShow() { this.lowdrelease(); wx.stopPullDownRefresh(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { this.lowdrelease(0); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { this.lowdrelease(this.data.wehicles.length); }, })
07-02 - 多个组件排一行换行问题?
如第一张图,换行后就另起一行了,希望效果能够像第二张图一样,依次排列后换行,求指教 [图片][图片] <view class="wehicle-top"> <text class="top">顶</text> <text class="start">{{wehicle.startPoint}}</text> <text class="arrow">→</text> <text class="end">{{wehicle.goal}}</text> <text wx:if="{{wehicle.carpool == '我要找人'}}" class="pass">({{wehicle.pass}}但是沃尔沃温热热私人而色色是二色)</text> <!--途径--> </view> WXSS代码: .wehicle-top{ display:flex; justify-content:flex-start; flex-flow:wrap; } .wehicle-top .top{ margin-right:10rpx; background-color:red; padding:0 10rpx; border-radius:10rpx; font-size:28rpx; color:#fff; } .wehicle-top .start{ font-size:32rpx; font-weight:700; margin-right:10rpx; } .wehicle-top .arrow{ font-size:32rpx; font-weight:700; margin-right:10rpx; } .wehicle-top .end{ font-size:32rpx; font-weight:700; margin-right:10rpx; } .wehicle-top .pass{ font-size:28rpx; font-weight:700; }
06-30 - 如何把components组件中的picker值保存到数据库中?
在components组件中定义了picker,在pages页面中,如何把picker中的值保存到数据库中? 图片 [图片][图片] 代码: components中: selector代码: <view class="section"> <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}"> <view class="section-picker"> <view class="picker"> {{arrays}} </view> <icon class="icon"></icon> </view> </picker> </view> js代码: Component({ /** * 组件的属性列表 */ properties: { array:{ type:Array, value:[] }, arrays:{ type:String, value:'' } }, /** * 组件的初始数据 */ data: { index:0 }, /** * 组件的方法列表 */ methods: { bindPickerChange(event){ console.log('picker发送选择改变,携带值为', event.detail.value) var that = this; var index = event.detail.value; var array = that.properties.array; that.setData({ arrays:array[index], // index: index }) var detail = {'index':index}; var options = {}; that.triggerEvent('carporate',detail,options) } } }) pickerday代码: <picker mode="date" fields="day" value="{{date}}" start="{{start}}" end="{{end}}" bindchange="onbindDataChange"> <view class="section-picker"> <view class="picker"> {{date}} </view> <icon class="icon"></icon> </view> </picker> js代码: var util = require('../../utils/util.js'); var minday = util.formatTime(new Date()).split(' ')[0]; var maxday = util.formatTime(new Date((new Date()).getTime()+(1000*60*60*24*62))).split(' ')[0]; Component({ /** * 组件的属性列表 */ properties: { date:{ type:String, value:'' } }, /** * 组件的初始数据 */ data: { // date:today, start: minday, end:maxday, }, /** * 组件的方法列表 */ methods: { onbindDataChange(event){ console.log(event); var value = event.detail.value; this.setData({ date:value }) }, } }) pages页面代码: <form bindsubmit="onReleaseEvent"> <view class="carpool-group"> <view class="carpool-title">拼车类型</view> <selector name="carpool" array="{{carpool}}" arrays="{{carpools}}" bindcarporate="onCarporateEvent"></selector> </view> <view class="carpool-group"> <view class="carpool-title">出发日期</view> <pickerday name="day" date="{{day}}"></pickerday> </view> <view class="carpool-group"> <view class="carpool-title">出发时间</view> <pickertime name="times" time="{{times}}"></pickertime> </view> <button class="btn" formType="submit">提交</button> </form> js代码: const db = wx.cloud.database() const app = getApp(); Page({ /** * 页面的初始数据 */ data: { carpool:['我要找车','我要找人','我找货车','我要找货'], carpools:'请选择拼车类型', day:'请选择出发日期', times:'请选择出发时间' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, onCarporateEvent(event){ console.log(event); var that = this; var index = event.detail.index; that.setData({ index:index }) }, /** * 发布信息 */ onReleaseEvent(event){ console.log(event); const that = this; const carpool = that.data.carpool[0]; // 如何获取拼车类型 const day = that.data.day; // 如何获取出发日期 const times = that.data.times; // 然后获取出发时间 const start = event.detail.value.start; const goal = event.detail.value.goal; const car = event.detail.value.car; const peopleNumber = event.detail.value.peopleNumber; const phone = event.detail.value.phone; const content = event.detail.value.content; const author = app.globalData.userInfo; db.collection("wehicle").add({ data:{ carpool:carpool, day:day, times:times, start:start, goal:goal, car:car, peopleNumber:peopleNumber, phone:phone, content:content, author:author } }) }, })
06-29 - 用户授权,获取app.globalData.userInfo为undefined?
查了很多资料说是异步问题,也做了修改,但还是为undefined。要怎么修改?求帮助、 app.js打印的图片 [图片] login.js打印的图片 [图片] // app.js App({ onLaunch:async function () { if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ env: '1g4z5k3lc74cf9e2', traceUser: true, }); } this.globalData = {}; await this.loadUserInfo(); console.log('loadUserInfo有没有执行',this.loadUserInfo); console.log('有没有获取到userInfo',this.globalData.userInfo); }, async loadUserInfo() { var that = this; let loginOpenid = await wx.cloud.callFunction({ name:'logins', }) console.log('获取用户openid',loginOpenid); that.globalData.openid = loginOpenid.result.openid; console.log('保存openid',that.globalData.openid); const loginRes = await wx.cloud.database().collection('login') .where({ _openid:'loginOpenid' }).get() console.log('查询是否有用户信息',loginRes); that.globalData.userInfo = loginRes.data[0]; console.log('保存用户信息到globalData',that.globalData.userInfo); }, is_login() { console.log('is_logn获取',this.globalData.userInfo); if (this.globalData.userInfo) { return true } else { return false } }, }) login.js代码 // pages/login/login.js const app = getApp(); const db = wx.cloud.database(); Page({ data: { }, onLoad(options) { }, // 获取头像 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 }) }) }, async login(event) { console.log(event); let nickName = await event.detail.value.nickName; console.log('用户名', nickName); if(!nickName){ wx.showToast({ title:'请填写昵称', icon:'error' }) return } if(!this.data.avatarUrl){ wx.showToast({ title:'请上传头像', icon:'error' }) return } let openid =await app.globalData.openid; console.log("获取app.globalData.openid",openid); try{ let existingUserQuery = await db.collection('login').where({ _openid:openid }).get(); console.log('获取用户信息',existingUserQuery) if(existingUserQuery.data.length > 0){ this.setData({ userInfo:existiongUserQuery.data[0], }); }else{ let newUser = { num:Date.now(), avatarUrl:this.data.avatarUrl, nickName:nickName, }; await db.collection('login').add({ data:newUser }); } }catch(err){ console.log('Error',err); } wx.showToast({ title:'登陆成功' }); setTimeout(()=>{ wx.navigateBack({}); },1500) }, }) user-center.js代码 const app = getApp(); console.log('是否有app信息',app) const db = wx.cloud.database(); Page({ data: { }, onLoad:async function(options) { console.log('是否有传递数据',app.is_login()); if(app.is_login()){ this.setData({ userInfo: app.globalData.userInfo, avatarUrl: app.globalData.userInfo.avatarUrl, nickName: app.globalData.userInfo.nickName }) } onuserInfo(e){ wx.navigateTo({ url:'/pages/login/login' }) },
06-08 - globalData打印出来是undefined?
写了段授权代码,设置全局配置时,is_login()中this.globalData.userInfo为undefined,在页面pages.user-center打印app.globalData.userInfo就是undefined,打印app.is_login()就是false,在pages.login页面中打印app.is_login()时为true,也就能够正常,打印app.globalData.userInfo又能够正常打印出来,请问这个问题怎么解决? 如图: [图片] app.js代码 App({ onLaunch: function () { if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ env: '', traceUser: true, }); } this.globalData = {}; this.loadUserInfo(); }, loadUserInfo() { //获取用户的openid var that = this; wx.cloud.callFunction({ name: 'login', success(res) { // console.log(res); that.globalData.openid = res.result.openid //查找数据库用户表里面是否有这个用户记录 wx.cloud.database().collection('login').where({ _openid: res.result.openid }).get({ success(result) { console.log(result) // that.globalData.userInfo = result.data[0] if(result.data[0]){ wx.setStorageSync('login',result.data[0]) // that.globalData.userInfo = wx.getStorageSync('userInfo') that.globalData.userInfo = result.data[0] console.log(that.globalData.userInfo); // 这里能够正常打印出来数据 } } }) } }) }, is_login() { console.log(this.globalData.userInfo); // 这里打印为undefined if (this.globalData.userInfo) { return true } else { return false } }, 云函数代码: const cloud = require('wx-server-sdk') cloud.init() const db = cloud.database(); // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() return { event, openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID, } } pages.login页面代码: const app =getApp(); const db = wx.cloud.database(); Page({ data: { }, onLoad(options) { }, // 获取头像 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.is_login()); // 在这里又能够正常打印出来 db.collection('login').where({ _openid:app.globalData.openid }).get({ success(res){ console.log(res) if(res.data.length == 0){ //添加记录到数据库 // var avatarUrl = that.data.avatarUrl; db.collection('login').add({ data:{ num:Date.now(),//!QQ号 avatarUrl:that.data.avatarUrl, nickName:nickName }, success(res){ console.log(res) wx.showToast({ title:'登陆成功', }) setTimeout(function(){ wx.navigateBack({}) },1500) } }) }else{ that.setData({ userInfo:res.data[0] }) } } }) },
06-02 - 在页面中globalData为null或者false?
在模拟器中,如果把我的页面放在前面展示,登陆成功后返回,页面没有获取到,如图一,如果首页放在前面展示,再打开我的页面就能够正常获取到,网上查了些资料,说是异步问题,没有处理过这种问题,代码改怎么写? [图片][图片] APP代码: App({ onLaunch: function () { if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ env:'', traceUser: true, }); } this.globalData = {}; this.loadUserInfo(); }, loadUserInfo(){ //获取用户的openid var that = this; wx.cloud.callFunction({ name:'login', success(res){ // console.log(res); that.globalData.openid = res.result.openid //查找数据库用户表里面是否有这个用户记录 wx.cloud.database().collection('login').where({ _openid:res.result.openid }).get({ success:result => { // console.log(result) that.globalData.userInfo = result.data[0] } }) } }) }, is_login(){ if(this.globalData.userInfo){ return true }else{ return false } }, }); wxml代码: <view class="userinfo-group"> <!-- 已登陆 --> <view class="user-group" wx:if="{{userInfo != null}}"> <image class="avatra" src="{{avatarUrl?avatarUrl:'../../images/avatar.png'}}"></image> <view class="right-group"> <view class="nickname">用户名:{{nickName}}</view> <view class="ID">用户ID:dfd9765490</view> </view> </view> <!-- 未登陆 --> <block wx:if="{{userInfo == null}}"> <view class="user-group" bind:tap="onuserInfo"> <image class="avatra" src="../../images/avatar.png"></image> <view class="right-group"> <view class="nickname">点击登录</view> <view class="ID">登录获取更多权限</view> </view> </view> </block> </view> JS代码: Page({ data: { }, onLoad(options) { console.log(app.is_login()); if(app.is_login()){ this.setData({ userInfo:app.globalData.userInfo, avatarUrl:app.globalData.userInfo.avatarUrl, nickName:app.globalData.userInfo.nickName }) } }, onuserInfo(){ wx.navigateTo({ url:'/pages/login/login' }) }, 代码片段 https://developers.weixin.qq.com/s/A59C3ym57VRA
05-29 - 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
05-18 - 页面中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 } });
04-03 - 在做个登陆授权页面时报错 globalThis is not defined?
不管是打开官方授权的代码片段也好,还是怎么样,当点击头像或者昵称时就报这个错, globalThis is not defined,请问各位大师,这个怎么解决? [图片][图片]
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