This repository has been archived on 2024-09-30. You can view files and clone it, but cannot push or open issues/pull-requests.
wxSmallApp/pages/home/home.js

107 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 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) => {
let code = res.data.code
console.log(res.data)
if (code == 0) {
console.log("请求菜单信息成功")
this.setData({ menuItems: res.data.data });
} else{
console.log("请求菜单信息失败")
}
}
});
},
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() {
}
})