//index.js
//获取应用实例
const app = getApp()
var util = require('../../utils/util.js');
Page({
data: {
motto: 'Hello World',
currentPage:1,
dataList:[],
imageUrls:[],
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
//绑定点击事件 燕潇洒
clickText:function(){
wx.showToast({
title: '我的小程序', //标题
icon: 'success', //图标,支持"success"、"loading"
image: '', //自定义图标的本地路径,image 的优先级高于 icon
duration: 2000, //提示的延迟时间,单位毫秒,默认:1500
mask: true, //是否显示透明蒙层,防止触摸穿透,默认:false
success: function () {
}, //接口调用成功的回调函数
fail: function () {
}, //接口调用失败的回调函数
complete: function () {
} //接口调用结束的回调函数
})
},
onLoad: function () {
//在onload生命周期中请求数据
this.getDataList();
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo: function(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
},
getDataList: function () {
var that = this;
wx.showLoading({
title: '加载中...',
})
wx.request({
url: 'https://www.apiopen.top/meituApi',
data:{
'page': 1
},
method: 'GET',
header: {
'content-type': 'application/json;charset=utf-8'
},
success: function (res) {
console.log(res);
if(res.data.code == 200){
var list = res.data.data;
//增加图片数据
for(var i = 0; i< list.length; i++){
that.data.imageUrls.push(list[i].url)
}
that.setData({
dataList: list,
currentPage: that.data.currentPage + 1
})
}
},
complete: function(){
wx.hideLoading();
}
})
},
onPullDownRefresh:function(){
// 显示顶部刷新图标
wx.showNavigationBarLoading();
var that = this;
wx.request({
url: 'https://www.apiopen.top/meituApi',
data:{
'page':1
},
method: "GET",
header: {
'content-type': 'application/json;charset=utf-8'
},
success: function (res) {
if (res.data.code == 200) {
var list = res.data.data;
that.setData({
dataList: list,
currentPage: that.data.currentPage + 1
})
}
// 隐藏导航栏加载框
wx.hideNavigationBarLoading();
// 停止下拉动作
wx.stopPullDownRefresh();
}
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
var that = this;
// 显示加载图标
wx.showLoading({
title: '玩命加载中',
})
wx.request({
url: 'https://www.apiopen.top/meituApi',
data:{
'page': that.data.currentPage
},
method: "GET",
header: {
'content-type': 'application/json;charset=utf-8'
},
success: function (res) {
if (res.data.code == 200) {
//接受新数据
var list = [];
//数据长度
var len = res.data.data.length;
for(var i=0;i<len;i++){
var obj = res.data.data[i];
list.push(obj);
//添加图片数据
that.data.imageUrls.push(res.data.data[i].url);
}
that.setData({
dataList: that.data.dataList.concat(list)
})
}
wx.hideLoading();
}
})
},
//图片点击事件
imgYu: function (event) {
var src = event.currentTarget.dataset.src;//获取data-src
// var imgList = event.currentTarget.dataset.list;//获取data-list
var imgList = this.data.imageUrls;//获取data-list
//图片预览
wx.previewImage({
current: src, // 当前显示图片的http链接
urls: imgList // 需要预览的图片http链接列表
})
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
我的小程序
共49个文件
png:14个
js:10个
json:9个
需积分: 50 6 下载量 25 浏览量
2018-10-12
13:37:13
上传
评论
收藏 109KB RAR 举报
温馨提示
小程序小项目,包含网络请求、页面跳转、页面间参数传递(数组/对象)等
资源推荐
资源详情
资源评论
收起资源包目录
xiaochengxu.rar (49个子文件)
xiaochengxu
images
bangbangtang.png 3KB
jiushui_2.png 2KB
niunai_1.png 1KB
kuaizi_1.png 1KB
chihuo.png 3KB
caomei.png 3KB
hongpingguo.png 3KB
niunai_2.png 1KB
shaoyao.png 2KB
kuaizi_2.png 1KB
pause.png 3KB
putao.png 4KB
yezhi.png 2KB
jiushui_1.png 2KB
timg.jpg 70KB
app.json 1KB
pages
index
index.js 5KB
index.json 80B
index.wxss 848B
index.wxml 430B
central
central.wxss 1KB
central.wxml 1KB
central.json 48B
central.js 4KB
logs
logs.js 276B
logs.json 54B
logs.wxml 179B
logs.wxss 114B
xiaosa
xiaosa.json 2B
xiaosa.wxss 655B
xiaosa.wxml 1KB
xiaosa.js 3KB
jinjie
jinjie.wxss 2KB
jinjie.js 3KB
jinjie.wxml 1KB
jinjie.json 73B
video
video.wxss 240B
video.wxml 331B
video.js 2KB
video.json 2B
detail
detail.js 2KB
detail.wxss 826B
detail.json 48B
detail.wxml 1KB
app.wxss 204B
app.js 1KB
project.config.json 618B
utils
util.js 491B
search.js 884B
共 49 条
- 1
资源评论
燕歆波
- 粉丝: 344
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功