• 微信小程序学习day01


     

    目标:

    1、实现轮播图

    2、实现首页九宫布局

    3、实现图片布局

    4、实现tabbar

    轮播图实现:

    1. <!--轮播图-->
    2. <swiper indicator-dots circular autoplay interval="3000" indicator-color="#fff">
    3. <swiper-item wx:for="{{swiperList}}" wx:key="id">
    4. <image src="{{item.path}}" ></image>
    5. </swiper-item>
    6. </swiper>

    indicator-dots:显示轮播图圆点

    circular:轮播图环绕展示

    autoplay:自动展示、

    interval设置轮播时间

    indicator-color:设置圆点颜色

    样式:设置轮播图高度,设置轮播图图片宽高

    swiper {

      height: 350rpx;

    }

    swiper image{

      height: 100%;

      width: 100%;

    }

     九宫格实现:

    1. <!--九宮格-->
    2. <view class="grid-list">
    3. <view class="grid-item" wx:for="{{gridList}}" wx:key="id">
    4. <image src="{{item.coverImg}}"></image>
    5. <text>{{item.name}}</text>
    6. </view>
    7. </view>

    样式:

    /**九宫格*/

    .grid-list{

      display: flex;/**弹性布局*/

      flex-wrap: wrap;/**让弹性盒元素在必要的时候拆行(换行)*/

      border-left: 1rpx solid #efefef; /**添加九宫格左侧 边框*/

      border-top: 1rpx solid #efefef;/**添加九宫格左顶部边框*/

    }

    .grid-item{

      width: 33.33%;  // 设置一行为3个按钮,各站三分之一

      height: 190rpx; // 各个元素高度

      display: flex;  // 弹性布局

      flex-direction: column;  // 设置主轴方向 横轴

      align-items: center;  /**设置侧轴上的子元素排列方式 垂直*/

      justify-content: center;  /**设置主轴上的子元素排列方式 上下*/

      border-right: 1rpx solid #efefef;  // 设置各个元素右边框

      border-bottom: 1rpx solid #efefef;  // 设置各个元素低部边框

      box-sizing: border-box; /**元素的总高度和宽度包含内边距和边框(padding 与 border) :*/

    }

    实现图片布局:

    1. <!--图片区-->
    2. <view class="image-box">
    3. <image src="/images/hunsha-1.jpg" mode="widthFix"></image>
    4. <image src="/images/hunsha-3.jpg" mode="widthFix"></image>
    5. </view>

    样式:

    .image-box{

      display: flex;  // 弹性布局

      padding: 20rpx 10rpx 0rpx 0rpx; /**定义元素边框与元素内容之间的空间  上、右、下、左*/

      justify-content: space-around;  // 均匀排列每个元素  每个元素周围分配相同的空间

    }

    .image-box image{

      width: 45%;

      border-radius: 20rpx;

    }

    /* 对齐方式 */
    justify-content: center;     /* 居中排列 */
    justify-content: start;      /* 从行首开始排列 */
    justify-content: end;        /* 从行尾开始排列 */
    justify-content: flex-start; /* 从行首起始位置开始排列 */
    justify-content: flex-end;   /* 从行尾位置开始排列 */
    justify-content: left;       /* 一个挨一个在对齐容器得左边缘 */
    justify-content: right;      /* 元素以容器右边缘为基准,一个挨着一个对齐, */

    /* 基线对齐 */
    justify-content: baseline;
    justify-content: first baseline;
    justify-content: last baseline;

    /* 分配弹性元素方式 */
    justify-content: space-between;  /* 均匀排列每个元素
                                       首个元素放置于起点,末尾元素放置于终点 */
    justify-content: space-around;  /* 均匀排列每个元素
                                       每个元素周围分配相同的空间 */
    justify-content: space-evenly;  /* 均匀排列每个元素
                                       每个元素之间的间隔相等 */
    justify-content: stretch;       /* 均匀排列每个元素
                                       'auto'-sized 的元素会被拉伸以适应容器的大小 */

    实现tabbar:

    直接在app.json中添加:最多5个,最少2个

    1. "tabBar": {
    2. "list": [
    3. {
    4. "pagePath": "pages/home/home",
    5. "text": "首页",
    6. "iconPath": "/images/icon/home.png",
    7. "selectedIconPath": "/images/icon/home-select.png"
    8. },{
    9. "pagePath": "pages/message/message",
    10. "text": "消息",
    11. "iconPath": "/images/icon/message.png",
    12. "selectedIconPath": "/images/icon/message-select.png"
    13. },{
    14. "pagePath": "pages/contact/contact",
    15. "text": "我的",
    16. "iconPath": "/images/icon/contact.png",
    17. "selectedIconPath": "/images/icon/contact-select.png"
    18. }
    19. ]
    20. },

  • 相关阅读:
    GBase 8s gcadmin之showdistribution命令解析
    regexp_split_to_table,regexp_split_to_array,array,unnest 使用
    Android R.fraction
    有什么拍照识别文字的软件?这篇文章看到就有收获哦
    Java 下数据业务逻辑开发技术 JOOQ 和 SPL
    中电金信技术实践|Redis哨兵原理及安装部署分享
    记Windows服务器Redis 6379被攻击 被设置主从模式同步项目数据
    关于yarn安装和运行的错误
    [附源码]计算机毕业设计学习帮扶网站设计与实现Springboot程序
    RabbitMQ的常见工作模式
  • 原文地址:https://blog.csdn.net/wdz985721191/article/details/127723605