微信小程序宠物论坛3

微信小程序宠物论坛3

首页模块

界面
在这里插入图片描述
首页展示所有帖子,下拉可以刷新。

JS部分

// 初始化数据化
const db = wx.cloud.database();
const cont = db.collection('post');

Page({
  data:{
    post:[],//帖子
    postnum:0,//帖子数量
    fintime:'',
  },

 //下拉刷新加载数据
  onPullDownRefresh: function () {
  wx.showNavigationBarLoading()
    wx.hideNavigationBarLoading();
    
    const _ = db.command
    wx.cloud.callFunction({
      name: 'getpost',
      data: {
        mark: 'get'
      }
    }).then(res => {
      this.setData({
        post: res.result.data
      })
    }).catch(err => { })

    setTimeout(function () {
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, 1500);
  },

  onLoad: function (options) {
    
    wx.cloud.callFunction({
      name: 'getpost',
      data: {
        mark: 'get'
      }
    }).then(res => {
      this.setData({
        post:res.result.data
      })
    }).catch(err => { })

  }
})


WXML部分

<view class="main" wx:for="{{post}}" wx:key="post">
<!-- 帖子ID显示 -->
<navigator url="../detail/detail?id={{item._id}}" open-type="navigate" >
<!-- 标题显示 -->
  <view class="title">{{item.title}}</view>
  <view class="pic">
  <!-- 显示第一张图片 -->
  <image style="width:30%;height:69px;" src="{{item.images[0]}}"/>
  <!-- 头像,发帖人昵称,时间  -->
  <view class="userinfo" style="flex-direction:row">
    <image class="userinfo-avatar" src="{{item.heads}}" background-size="cover"></image>
    <text decode="{{true}}" class="userinfo-nickname">&nbsp;&nbsp;{{item.nickname}}</text>
    <text decode="{{true}}" class="userinfo-time">&nbsp;&nbsp;&nbsp;&nbsp;{{item.time}}</text> 
  </view>
</view>
<view class="line"></view>
</navigator>
</view>


WXSS部分

.title{
  font-weight: bold;
}
.desc{
font-size:70%;
}

.userinfo-avatar {
  width: 30rpx;
  height: 30rpx;
  border-radius: 50%;
}

.userinfo-nickname {
  font-weight:bold;
  font-size:75%;
  color: black;
  margin-bottom:30px;
}
.userinfo-time{
 font-size:65%;
 padding-bottom:40px
}

.line {
  border: 1px solid #ccc;
  opacity: 0.2;
}

.main{
  padding-left: 4%;
  padding-right: 4%
}

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值