• 小程序常用组件小结


    常用的视图容器类组件

    view

    1. 类似与HTML中的div,是一个块级元素
    2. 常用来实现页面的布局效果
    3. 普通视图区域

    scroll-view

    1. 可滚动的视图区域
    2. 常用来实现滚动列表效果
    <scroll-view class="container1" scroll-y>
    <view>A</view>
    <view>B</view>
    <view>C</view>
    </scroll-view>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    .container1 {
        /* display: flex;
        justify-content: space-around; */
        border: 1px solid #ccc;
        width: 100px;
        height: 120px;
    }
    .container1 view {
        width: 100px;
        height: 100px;
        line-height: 100px;
        text-align: center;
    }
    .container1 view:nth-child(1) {
        background-color: lightgreen;
    }
    .container1 view:nth-child(2) {
        background-color: blue;
    }
    .container1 view:nth-child(3) {
        background-color: pink;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    实现效果如下:
    在这里插入图片描述

    swiper和swiper-item

    轮播图容器组件和轮播图item组件

    在这里插入图片描述

    <swiper class="swiper_container" indicator-dots indicator-color="#fff" indicator-active-color="gray" autoplay="true" interval="2000" circular>
        <swiper-item>
            <view class="item">A</view>
        </swiper-item>
        <swiper-item>
            <view class="item">B</view>
        </swiper-item>
        <swiper-item>
            <view class="item">C</view>
        </swiper-item>
    </swiper>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    .swiper_container {
        height: 150px;
    }
    .item {
        height: 100%;
        line-height: 150px;
        text-align: center;
    }
    swiper-item:nth-child(1) .item {
        background-color: green;
    }
    swiper-item:nth-child(2) .item {
        background-color: rgb(68, 227, 248);
    }
    swiper-item:nth-child(3) .item {
        background-color: rgb(233, 35, 134);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

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

    常用的其他组件

    button

    1. 按钮组件
    2. 功能比HTML中的button按钮丰富
    3. 通过open-type属性可以调用微信提供的各种功能(客服、转发、获取用户授权、获取用户信息等)

    简单demo:

    <rich-text nodes="<h1 style='color:red'>标题</h1>"></rich-text>
    
    <view>~~~~~~~~通过type指定按钮类型~~~~~~~~</view>
    <button>普通的按钮</button>
    <button type="primary">主色调按钮</button>
    <button type="warn">警告按钮</button>
    
    <view>~~~~~~~通过size="mini"小尺寸按钮~~~~~~~</view>
    <button size="mini">普通的按钮</button>
    <button type="primary" size="mini">主色调按钮</button>
    <button type="warn" size="mini">警告按钮</button>
    
    <view>~~~~~~~plain镂空按钮~~~~~~~</view>
    <button size="mini" plain>普通的按钮</button>
    <button type="primary" size="mini" plain>主色调按钮</button>
    <button type="warn" size="mini" plain>警告按钮</button>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    在这里插入图片描述

    image

    1. 图片组件
    2. image组件默认宽度为300px、高度为240px

    在这里插入图片描述

    navigator(待补充)

    1. 页面导航组件
    2. 类似于HTML中的a链接

    text

    文本组件,相当于html中的span标签,它的一个属性selectable可以实现长按选中的效果

    rich-text

    这个文本组件中具有一个属性:nodes,nodes中可以写一些视图标签,并且可以直接写一些样式

    <rich-text nodes="<h1 style='color:red'>标题</h1>"></rich-text>
    
    • 1

    在这里插入图片描述

  • 相关阅读:
    字符串总结
    0成本截流的三种方法,挣钱从引流开始
    NOIP 2012 普及组初赛 第28题 排列数
    程序内hook键盘
    功能测试做自动化必须了解的3件事,受用终生【建议收藏】
    Autosar Configuration(九) Security之不修改DBC属性配置SecOC安全报文、同步报文和同步请求报文
    腾讯云服务器南京地域详细介绍、测试IP和Ping值测速
    为什么你学了那么多,却没赚到钱?
    为什么C4D能成为电商设计的王者?
    C++ vs Rust vs Go性能
  • 原文地址:https://blog.csdn.net/m0_52040370/article/details/125470779