美文网首页微信小程序笔记
小程序(三)新闻列表

小程序(三)新闻列表

作者: 小狐狸ry | 来源:发表于2018-12-28 18:05 被阅读0次

新建newslist目录

  • 新建目录、文件步骤如同小程序(二)中所介绍
  • 为使编译后看到的页面为当前目录的wxml页面,修改app.json文件中的“pages”配置项,将所要显示的页面路径放在最上方
"pages":[
  "pages/newslist/newslist",
  "pages/index/index"
]

新闻列表的效果图如 图3-1 所示

3-1 效果图

首先是导航栏的标题与背景色

newslist.json

{
  "navigationBarBackgroundColor": "#405f80",
  "navigationBarTitleText":"文与字"
}

因为我们需要的是当前页面导航栏的标题与背景色,所以只需要在当前的 json 配置文件中修改/加入即可。
注:页面的配置只能设置 app.json 中部分 window 配置项的内容,页面中配置项会覆盖 app.json 的 window 中相同的配置项。页面配置文件中不需要写入 "window":{}

使用 swiper组件完成图片轮播

newslist.wxml

  <!-- 当属性值涉及到 布尔类型的否定式 需加 {{}}  eg:{{false}} -->
<swiper vertical='{{false}}' indicator-dots='ture' autoplay='true' interval='2000'>
  <!-- vertical页面是否纵向滚动 indicator-dots面板指示点,autoplay是否自动滚动,interval滚动时间,默认5000毫秒 -->
    <swiper-item>
      <image src='/images/wx.png'></image>
    </swiper-item>
    <swiper-item>
      <image src='/images/vr.png'></image>
    </swiper-item>
    <swiper-item>
      <image src='/images/iqiyi.png'></image>
    </swiper-item>
  </swiper>

newslist.wxss

swiper{
  height: 600rpx;
}
image{
  width: 100%;
  height: 600rpx;
}

新闻列表

newslist.wxml

  <view class='post-container'>
    <view class='post-author-date'>
      <image class='post-author' src='/images/avatar/avatar.jpg'></image>
      <text class='post-date'>Nov 25 2016</text>
    </view>
    <text class='post-title'>正是虾肥蟹壮时</text>
    <image class='post-image' src='/images/post/crab.png'></image>
    <text class='post-title'>菊黄蟹正肥,品尝秋之味。徐志摩把“看初花的荻芦”和“到楼外楼吃蟹”并列为</text>
    <view class='post-like'>
      <image class='post-like-image' src='../../images/icon/chat.png'></image>
      <text class='post-like-font'>92</text>
      <image class='post-like-image' src='../../images/icon/view.png'></image>
      <text class='post-like-font'>65</text>
    </view>
  </view>

newslist.wxss

.post-container{
  display: flex;
  flex-direction: column;
  margin-top: 20rpx;
  margin-bottom: 40rpx;
  background-color: #fff;
  border-bottom: 1px solid #ededed;
  border-top: 1px solid #ededed;
  padding-bottom: 5px;  
}
.post-author-date{
  margin: 10rpx 0 20rpx 10rpx;
}
.post-author{
  width: 60rpx;
  height: 60rpx;
  vertical-align: middle;
  border-radius: 50%;
}
.post-date{
  margin-left: 20rpx;
  vertical-align: middle;
  margin-bottom: 5px;
  font-size: 26rpx;
}
.post-title{
  font-size: 34rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
  margin-left: 10px;
}
.post-image{
  margin-left: 16px;
  width: 100%;
  height: 340rpx;
  margin: auto 0;
  margin-bottom: 15px;
}
.post-content{
  color: #666;
  font-size: 28rpx;
  margin-bottom: 20rpx;
  margin-left: 20rpx;
  letter-spacing: 2rpx;
  line-height: 20rpx;
}
.post-like{
  font-size: 13px;
  flex-direction: row;
  line-height: 16px;
  margin-left: 10px;
}
.post-like-image{
  height: 16px;
  width: 16px;
  margin-right: 8px;
  vertical-align: middle;
}
.post-like-font{
  vertical-align: middle;
  margin-right: 20px;
}

好了 3-1所示的效果图到此就做好了,图片自己扒拉几张就好了。

相关文章

网友评论

    本文标题:小程序(三)新闻列表

    本文链接:https://www.haomeiwen.com/subject/kjoqkqtx.html