在win微信开发工具上 下拉刷新会连续触发
[代码]var[代码] [代码]Service = require([代码][代码]'../../utils/Service.js'[代码][代码]);[代码] [代码]var[代码] [代码]util = require([代码][代码]'../../utils/util.js'[代码][代码]);[代码] [代码]Page({[代码] [代码]/**[代码] [代码] [代码][代码]* 页面的初始数据[代码] [代码] [代码][代码]*/[代码] [代码]data: {[代码] [代码]getDataState: [代码][代码]true[代码][代码],[代码] [代码]globalLoading: [代码][代码]true[代码][代码],[代码] [代码]animationBeingLoaded: {},[代码] [代码]BeingLoadedState: {[代码] [代码]text: [代码][代码]'没有更多数据'[代码][代码],[代码] [代码]show: [代码][代码]false[代码][代码],[代码] [代码]icon: [代码][代码]false[代码] [代码]},[代码] [代码]movieData: [代码][代码]null[代码][代码],[代码] [代码]FilmStars: {}[代码] [代码]},[代码] [代码]/**[代码] [代码] [代码][代码]* 生命周期函数--监听页面加载[代码] [代码] [代码][代码]*/[代码] [代码]onLoad: [代码][代码]function[代码] [代码](options) {[代码] [代码]wx.setNavigationBarTitle({[代码] [代码]title: [代码][代码]'豆瓣电影 新片榜'[代码] [代码]});[代码] [代码]this[代码][代码].getData();[代码] [代码]},[代码] [代码]/**[代码] [代码] [代码][代码]* 生命周期函数--监听页面初次渲染完成[代码] [代码] [代码][代码]*/[代码] [代码]onReady: [代码][代码]function[代码] [代码]() {[代码] [代码]},[代码] [代码]/**[代码] [代码] [代码][代码]* 生命周期函数--监听页面显示[代码] [代码] [代码][代码]*/[代码] [代码]onShow: [代码][代码]function[代码] [代码]() {[代码] [代码]},[代码] [代码]/**[代码] [代码] [代码][代码]* 生命周期函数--监听页面隐藏[代码] [代码] [代码][代码]*/[代码] [代码]onHide: [代码][代码]function[代码] [代码]() {[代码] [代码]},[代码] [代码]/**[代码] [代码] [代码][代码]* 生命周期函数--监听页面卸载[代码] [代码] [代码][代码]*/[代码] [代码]onUnload: [代码][代码]function[代码] [代码]() {[代码] [代码]},[代码] [代码]onPullDownRefresh: [代码][代码]function[代码] [代码]() {[代码] [代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码] [代码]wx.startPullDownRefresh();[代码] [代码]if[代码][代码](that.data.getDataState){[代码] [代码]that.getData();[代码] [代码]}[代码][代码]else[代码][代码]{[代码] [代码]console.log([代码][代码]"操作频繁"[代码][代码]);[代码] [代码]}[代码] [代码]},[代码] [代码]/**[代码] [代码] [代码][代码]* 自定义函数[代码] [代码] [代码][代码]*/[代码] [代码]// 请求数据[代码] [代码]getData: [代码][代码]function[代码] [代码]() {[代码] [代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码] [代码]that.setData({[代码] [代码]getDataState: [代码][代码]false[代码] [代码]});[代码] [代码]wx.request({[代码] [代码]url: Service.DoubanApi.new_movies,[代码] [代码]method: [代码][代码]'GET'[代码][代码],[代码] [代码]data: {},[代码] [代码]header: {[代码] [代码]'content-type'[代码][代码]: [代码][代码]'json'[代码] [代码]},[代码] [代码]success: [代码][代码]function[代码] [代码](res) {[代码] [代码]console.log(res);[代码] [代码]that.setData({[代码] [代码]getDataState: [代码][代码]true[代码] [代码]});[代码] [代码]if[代码] [代码](res.statusCode == 200) {[代码] [代码]var[代码] [代码]ToastText = [代码][代码]''[代码][代码];[代码] [代码]if[代码][代码](that.data.movieData != [代码][代码]null[代码][代码]){[代码] [代码]wx.showToast({[代码] [代码]title: [代码][代码]'刷新成功'[代码][代码],[代码] [代码]icon: [代码][代码]'success'[代码][代码],[代码] [代码]duration: 1000[代码] [代码]})[代码] [代码]}[代码] [代码]that.FilmStars(res.data.subjects);[代码] [代码]that.setData({[代码] [代码]globalLoading: [代码][代码]false[代码][代码],[代码] [代码]movieData: res.data.subjects,[代码] [代码]BeingLoadedState: {[代码] [代码]text: [代码][代码]'没有更多数据'[代码][代码],[代码] [代码]show: [代码][代码]true[代码][代码],[代码] [代码]icon: [代码][代码]false[代码] [代码]}[代码] [代码]});[代码] [代码]} [代码][代码]else[代码] [代码]{[代码] [代码]wx.showToast({[代码] [代码]title: Service.CodeCallback(res.statusCode),[代码] [代码]icon: [代码][代码]'none'[代码] [代码]})[代码] [代码]}[代码] [代码]},[代码] [代码]fail: [代码][代码]function[代码] [代码](err){[代码] [代码]wx.showToast({[代码] [代码]title: [代码][代码]"加载失败"[代码][代码],[代码] [代码]icon: [代码][代码]'none'[代码] [代码]})[代码] [代码]},[代码] [代码]complete: [代码][代码]function[代码] [代码](con) {[代码] [代码]wx.stopPullDownRefresh();[代码] [代码]}[代码] [代码]})[代码] [代码]},[代码] [代码]// 影片星星[代码] [代码]FilmStars: [代码][代码]function[代码][代码](subjects){[代码] [代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码] [代码]var[代码] [代码]images = that.data.FilmStars;[代码] [代码]for[代码][代码]([代码][代码]var[代码] [代码]i=0; i<subjects.length; i++){[代码] [代码]images[i] = util.fiveStar_rating(subjects[i].rating.max,subjects[i].rating.min,subjects[i].rating.average)[代码] [代码]}[代码] [代码]that.setData({[代码] [代码]FilmStars: images[代码] [代码]});[代码] [代码]}[代码] [代码]})[代码][图片] [图片]