This repository has been archived on 2024-09-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
wxSmallApp/pages/home/home.js
2024-01-06 10:35:41 +08:00

100 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// pages/personal/personal.js
import { requestUrl } from '../../utils/config.js';
Page({
/**
* 页面的初始数据
*/
data: {
menuItems: [],
swiperList:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getMenu();
this.getSwiperList();
},
getMenu(){
wx.request({
url: requestUrl + '/api/get-menu', // 更改为你的实际API地址
success: (res) => {
console.log(res.data)
this.setData({ menuItems: res.data.data });
}
});
},
getSwiperList(){
let that = this; // 在回调中使用this所以需要先保存它的引用
wx.request({
url: requestUrl + '/api/get-swiper-list', // 确保requestUrl已定义且正确
method: "GET",
success(res) {
console.log(res.data); // 打印响应内容
// 假设返回的数据结构是{ image_ids: [...] }
if(res.data.code == 0 && res.data.msg == "ok"){
console.log("请求成功")
that.setData({swiperList:res.data.data})
} else {
// 处理错误或空数据的情况
console.log("Received empty or incorrect format data");
}
},
fail(error) {
// 请求失败的处理
console.error("Request failed", error);
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})