微信小程序学习笔记-(11)-仿糗事百科

API接口地址;
http://m2.qiushibaike.com/article/list/{type}?type=refresh&page={page}&count={count}
参数type为类型,latest最新、text文本、image图片、video视频
参数page为页码;参数count为每页数量
示例:http://m2.qiushibaike.com/article/list/text?type=refresh&page=1&count=12

一,初始化

删除index和log页面,然后新建home页面,因为是一个页面内滑动,所以有好多个wxml文件
在这里插入图片描述

二,滑动切换页面的实现

在这里插入图片描述
在这里插入图片描述
相应的wxml代码:

<view class="bg">
  <view class="nav">
  <!-- 水平滚动 -->
    <scroll-view scroll-x="true" class="scroll-view">
      <view class="scroll-view">
        <view>
          <view class="{{currentIndex==0?'select':'normal'}}" bindtap="switchNav" id="0">Vip专享</view>
        </view>
        <view>
          <view class="{{currentIndex==1?'select':'normal'}}" bindtap="switchNav" id="1">视频</view>
        </view>
        <view>
          <view class="{{currentIndex==2?'select':'normal'}}" bindtap="switchNav" id="2">图片</view>
        </view>
        <view>
          <view class="{{currentIndex==3?'select':'normal'}}"  bindtap="switchNav" id="3">糗事</view>
        </view>
        <view>
          <view class="{{currentIndex==4?'select':'normal'}}" bindtap="switchNav" id="4">精华</view>
        </view>
        <view>
          <view class="{{currentIndex==5?'select':'normal'}}" bindtap="switchNav" id="5">穿越</view>
        </view>
        <view>
          <view class="{{currentIndex==6?'select':'normal'}}" bindtap="switchNav" id="6">爆料</view>
        </view>
      </view>
    </scroll-view>
  </view>
  <!-- 审核 -->
  <view class="opr"></view>
  <!-- 添加 -->
  <view class="add">+</view>
</view>

<!-- 内容区域 -->
<swiper current="{{currentIndex}}" style="height:{{winHeight}}px">
  <swiper-item>
    <!-- 引入其他页面加载进来 -->
    <include src="vip.wxml"></include>
  </swiper-item>
  <swiper-item>
    <include src="video.wxml"></include>
  </swiper-item>
  <swiper-item>
    <include src="image.wxml"></include>
  </swiper-item>
  <swiper-item>我是糗事百科</swiper-item>
  <swiper-item>我是精华内容</swiper-item>
  <swiper-item>我是穿越内容</swiper-item>
  <swiper-item>我是爆料内容</swiper-item>
</swiper>

css代码:

/* pages/home/home.wxss */
.bg{
  height:50px;
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  background-color: #ffba1e;
  color: #fff;
}
.nav{
  width: 70%;
  height: 100%;
  overflow: hidden;
}
.scroll-view{
  display: flex;
  margin-left: 10px;
  height: 100%;
}
.select{
  width: 70px;
  height: 100%;
  line-height: 50px;
  text-align: center;
  /* padding: 0 10px; */
  font-weight: bold;
  font-size: 14px;
  border-bottom: 8px solid #fff;
  box-sizing: border-box;
}
.normal{
  width: 70px;
  height: 100%;
  line-height: 50px;
  text-align: center;
  /* padding: 0 10px; */
  font-size: 14px;
  box-sizing: border-box;
}
.opr{
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: white;
  color: #ffba1e;
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  line-height: 20px;
  margin: 0 10px;
}
.add{
  width: 20%;
  height: 50px;
  color: white;
  font-size: 50px;
  font-weight: bold;
  text-align: right;
  line-height: 50px;

}

js代码:

data: {
    currentIndex:0,
    winHeight:0
  },
  // tab按钮切换页面
  switchNav(e){
    if(this.data.currentIndex==e.target.id){
      return
    }else{
      this.setData({
        currentIndex:e.target.id
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //保存this(箭头函数会影响this)
    var page=this
    //获取系统信息(用什么设备打开的这个页面)
    wx.getSystemInfo({
      success (res) {
        //获取可使用的窗口的宽高
        page.setData({
          winHeight:res.windowHeight
        })
      }
    })
  },

三,首页内容的实现

在这里插入图片描述
还是普通的页面渲染,唯一需要注意的是这里依旧使用wx.request来获取数据
在这里插入图片描述

四,上拉加载更多的实现

第一步:先在该页面的.json文件中增加配置;

在这里插入图片描述

第二步:设置加载的代码

超过这个页码就不加载了。
在这里插入图片描述

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值