<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就可以
想要获得更多资料的 请微信搜索公众号 【热血科技】,关注一下即可。