微信小程序上拉加载

本文介绍了一个用于展示小程序考试题目的WXML组件实现方案,包括题目、选项及答案展示,并通过分页请求动态加载题目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<view class=''>
    <view class='question-chid' wx:for='{{array}}' wx:for-index="idx" wx:key='{{index}}'>
        <view class='title'>
            <text class='xuhao'>{{idx+1}}、</text>
            <text class='timu'>{{item.timu}}</text> 
        </view>
        <view class='answer'>
            <text class='answer-one'>A:{{item.daan}}</text>
            <text class='answer-one'>B:{{item.daan1}}</text>
            <text class='answer-one'>C:{{item.danan2}}</text>
            <text class='answer-one'>D:{{item.daan3}}</text>
        </view>
        <view class='isAnswer'>
            <text style='font-size:36rpx;'>正确答案:</text>
            <text style='color:red;'>{{item.zqdanan}}</text>
        </view>
    </view>
</view>
/* hotblood_gongkao/pages/question/question.wxss */
.question{
    height: 100%;
    width: 100%;
}
.question-chid{
    width: 90%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    margin: 40rpx auto;
}
.title{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    font-size: 36rpx;
    color: #eb4a04;

}
.answer{
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    font-size: 32rpx;
    margin-top: 30rpx;
}

.isAnswer{
    display: flex;
    flex-direction: row;
    margin-top:30rpx; 
}
// hotblood_gongkao/pages/question/question.js
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        id:null,
        page:1//初始页码
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        //设置title
        wx.setNavigationBarTitle({
            title: options.title,
        })
        //当前分类ID
        this.setData({
            id:options.id
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.question(this.data.page);
    },
    
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function(e) {
        var page = this.data.page;
        page = page + 1;
        this.setData({
            page:page
        })
        this.question(page);
    },
    //分页请求题目
    question: function (page) {
        var _this = this;
        var array = _this.data.array;//数据源
        wx.showLoading({
            title: '加载中...',
        })
        app.util.request({
            'url': 'entry/wxapp/Answer',//接口地址
            'data': {
                id: _this.data.id,//类别ID
                page: page//页码
            },
            method: "POST",
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: function (res) {
                wx.hideLoading();
                if(page == 1){//判断当前页码是不是为1,为1时不需要Push数据源
                    if(res.data.data.data.length == 0){
                        wx.showToast({
                            title: '暂无题目',
                            icon: 'none',
                            duration: 2000
                        })
                    }else{
                        _this.setData({
                            array: res.data.data.data
                        })
                    }
                    
                }else{
                    for (let i = 0; i < res.data.data.data.length; i++) {
                        array.push(res.data.data.data[i]);
                    }
                    _this.setData({
                        array: array
                    })
                }
                
                
            },
            fail: res => {
                wx.hideLoading();
                console.log(res);

            }
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})

app.util.request  这个你们就用wx.request就可以

想要获得更多资料的  请微信搜索公众号 【热血科技】,关注一下即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值