// 引入请求接口方法
import http from "../../utils/http"
// console.log(http)
Page({
/**
* 页面的初始数据
*/
data: {
// 初始化故事分类默认下标
index: 0,
// 故事分类数据
cateList: []
},
// 用户选择分类数据
changeCate(e) {
// 1.同步默认下标
let index = e.detail.value
this.setData({index})
// 2.跳转到故事列表页面 携带分类id
wx.navigateTo({
url: '../list/list?params='+JSON.stringify(this.data.cateList[index])
})
},
// 定义获取故事分类数据的方法
async getCateS() {
// 1.原生写法
// wx.request({
// url: 'https://api.aslegou.top/api/storycatelist',
// method: "get",
// success: res => {
// // 赋值数据个页面
// this.setData({cateList:res.data.list})
// },
// fail: err => console.log(res)
// })
// 2.promise
http({
url:"storycatelist"
})
.then(res=>{
// 赋值数据个页面
this.setData({cateList:res.list})
// 将获取到的数据缓存早本地一份
wx.setStorageSync('cateList', res.list)
})
.catch(err=>console.log(err))
// 3.async
// let res = await http({url:"storycatelist"})
// console.log(res)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 获取本地缓存中的故事分类数据 [{},{}]
let cateList = wx.getStorageSync('cateList') || ""
if(cateList == ""){
// 获取故事分类数据
this.getCateS()
console.log('走请求了')
}else{
// 缓存中直接赋值给页面即可
this.setData({cateList})
console.log('走缓存了')
}
console.log(cateList)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序,小故事程序
共30个文件
jpg:7个
json:7个
js:6个
需积分: 18 1 下载量 160 浏览量
2023-03-02
10:37:44
上传
评论
收藏 1.25MB ZIP 举报
温馨提示
微信小程序,小故事程序,简单的页面,包括主页,列表页,个人主页等页面,并能实现各个页面的跳转等。
资源推荐
资源详情
资源评论
收起资源包目录
story.zip (30个子文件)
story
sitemap.json 191B
project.private.config.json 789B
pages
index
index.wxml 457B
index.js 3KB
index.json 107B
index.wxss 521B
list
list.json 75B
list.wxss 587B
list.js 2KB
list.wxml 532B
app.json 334B
project.config.json 1KB
app.js 539B
utils
tip.js 353B
http.js 745B
app.wxss 194B
components
list
list.json 52B
list.wxss 301B
list.js 427B
list.wxml 224B
story
laba.jpg 17KB
sch.png 2KB
b1.jpg 346KB
b2.jpg 286KB
fx.png 1KB
shubiao.jpg 38KB
b3.jpg 266KB
b5.jpg 160KB
b4.jpg 159KB
sc.png 1KB
共 30 条
- 1
资源评论
前端-邵
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功