(四)、首页持续完善【uniapp+uinicloud多用户社区博客实战项目(完整开发文档-从零到完整项目)】

有目标就不怕路远。年轻人.无论你现在身在何方.重要的是你将要向何处去。只有明确的目标才能助你成功。没有目标的航船.任何方向的风对他来说都是逆风。因此,再遥远的旅程,只要有目标.就不怕路远。没有目标,哪来的劲头?一车尔尼雷夫斯基

导读:本篇文章讲解 (四)、首页持续完善【uniapp+uinicloud多用户社区博客实战项目(完整开发文档-从零到完整项目)】,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

1,引入uview组件tabs标签

1.1,代码

template内容代码:

 <!-- 引入uview组件tabs标签 -->
    <view class="topnav">
      <u-tabs :list="navlist" :activeStyle="{
    				color: '#333',
    				fontWeight: 'bold',
    				transform: 'scale(1.08)'
    			}" :inactiveStyle="{
    				color: '#888',
    				transform: 'scale(1)'
    			}" @click="clickNav"></u-tabs>
    </view>

js内容代码:

<script>
  export default {
    data() {
      return {
        navlist: [{
            name: "最新",
            type: "publish_date"
          },
          {
            name: "热门",
            type: "view_count",
            badge: {
              isDot: true
            }
          }
        ]
      };
    },
    onLoad() {

    },
    methods: {
      clickNav(e) {
        console.log(e)
      },
    }
  };
</script>

css内容代码:

<style lang="scss" scoped>
  .home {
    .topnav {
      margin-bottom: 30rpx;
    }
  }
</style>

1.2,效果

在这里插入图片描述

2,引入uview组件Skeleton 骨架屏

template内容代码:

    <!-- 引入uview组件Skeleton 骨架屏 -->
    <view class="loadingState" v-show="loadState">
      <u-skeleton rows="4" title loading></u-skeleton>
    </view>

data中定义loadStae属性

loadState: false

css样式

    .loadingState {
      padding: 30rpx;
    }

效果:
在这里插入图片描述

3,中间内容部分抽离为公共组件

3.1,新建blog-item子组件

首先在项目根目录下新建文件夹components
然后在components文件夹中新建子组件blog-item:
在这里插入图片描述
在这里插入图片描述

3.2,blog-item子组件完整代码
<template>
  <view class="blogitem">
    <!-- 头部用户信息 -->
    <view class="head">
      <view class="userinfo">
        <!-- 右边头像 -->
        <view class="avatar">
          <image src="../../static/images/pic2.jpg" mode="aspectFill"></image>
        </view>
        <!-- 右边用户名称 -->
        <view class="name">
          wangwu
        </view>
        <!-- 右边时间  定制格式化 -->
        <view class="time">
          <uni-dateformat :date="Date.now()" format="MM月dd hh:mm" :threshold="[60000,3600000*24*30]"></uni-dateformat>
        </view>
      </view>
      <!-- 左边 三个点  更多 -->
      <view class="more" @click="clickMore">
        <text class="iconfont icon-ellipsis"></text>
      </view>
    </view>
    <!-- 中间内容 -->
    <view class="body">
      <!-- 上 标题 -->
      <view class="title">title</view>
      <!-- 中 内容 -->
      <view class="text">
        <view class="t">descriptiondescriptiondescriptiondescriptiondescriptiondescriptiondescription</view>
      </view>
      <!-- 下 缩略图 -->
      <view class="piclist">
        <view class="pic" :class="picArr.length==1 ? 'only': ''" v-for="(item,index) in picArr" :key="index">
          <image src="../../static/images/pic2.jpg" mode="aspectFill"></image>
        </view>
      </view>
    </view>
    <!-- 底部 信息内容 -->
    <view class="info">
      <!-- 游览量 -->
      <view class="box">
        <text class="iconfont icon-a-27-liulan"></text> <text>232</text>
      </view>
      <!-- 评论数 -->
      <view class="box">
        <text class="iconfont icon-a-5-xinxi"></text>
        <text>232评论</text>
      </view>
      <!-- 点赞量 -->
      <view class="box">
        <text class="iconfont icon-a-106-xihuan"></text>
        <text>22点赞</text>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "blog-item",
    data() {
      return {
        picArr: [1, 2, 3]
      };
    }
  }
</script>

<style lang="scss">
  .blogitem {
    .head {
      display: flex;
      font-size: 32rpx;
      align-items: center;
      justify-content: space-between;
      .userinfo {
        display: flex;
        align-items: center;
        .avatar {
          width: 40rpx;
          height: 40rpx;
          border-radius: 50%;
          border-radius: 50%;
          overflow: hidden;
          image {
            width: 100%;
            height: 100%;
            display: block;
          }
        }
        .name {
          color: #222;
          padding-left: 10rpx;
        }
        .time {
          color: #888;
          font-size: 22rpx;
          padding-left: 20rpx;
        }
      }
      .more {
        padding: 5rpx;
        .iconfont {
          font-size: 50rpx;
          color: #888;
        }
      }
    }
    .body {
      padding: 15rpx 0 30rpx;
      .title {
        font-size: 44rpx;
        color: #000;
        font-weight: 600;
        text-align: justify;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .text {
        padding-top: 10rpx;
        padding-bottom: 10rpx;
        font-size: 30rpx;
        text-align: justify;
        color: #888;
        .t {
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
      .piclist {
        display: flex;
        padding-top: 20rpx;
        .pic {
          width: 225rpx;
          height: 225rpx;
          margin-right: 6rpx;
          overflow: hidden;
          image {
            width: 100%;
            height: 100%;
          }
          &:first-child {
            border-radius: 20rpx 0 0 20rpx;
          }
          &:last-child {
            border-radius: 0 20rpx 20rpx 0;
          }
          &.only {
            border-radius: 20rpx;
          }
        }
      }
    }
    .info {
      display: flex;
      align-items: center;
      justify-content: space-around;
      font-size: 26rpx;
      color: #333;
      .box {
        display: flex;
        align-items: center;
        padding: 15rpx 0 5rpx;
        flex: 1;
        display: flex;
        justify-content: center;
        .iconfont {
          font-size: 40rpx;
          padding-right: 10rpx;
        }
      }
      .box.active {
        color: #0199FE
      }
    }
  }
</style>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/135739.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!