4.小程序9类组件和三类api

在这里插入图片描述

2.常用的视图容器类组件

在这里插入图片描述

2.1.view 组件的基本使用

在这里插入图片描述

<view class="container1">
    <view>A</view>
    <view>B</view>
    <view>C</view>
</view>
.container1 view {
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
}
.container1 view:nth-child(1) {
    background-color: chartreuse;
}
.container1 view:nth-child(2) {
    background-color: cornflowerblue;
}
.container1 view:nth-child(3) {
    background-color: lightpink;
}
.container1 {
    display: flex;
    justify-content: space-around;
}

2.2 scroll-view 组件的基本使用

在这里插入图片描述

scroll-y: 竖着滚动

<scroll-view class="container1" scroll-y>
    <view>A</view>
    <view>B</view>
    <view>C</view>
</scroll-view>
.container1 view {
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
}
.container1 view:nth-child(1) {
    background-color: chartreuse;
}
.container1 view:nth-child(2) {
    background-color: cornflowerblue;
}
.container1 view:nth-child(3) {
    background-color: lightpink;
}
.container1 {
    border: 1px solid red;
    width: 100px;
    height: 120px;
}

2.3.swiper 和swiper-item组件的基本使用

在这里插入图片描述
实现轮播图

<!-- 轮播图的结构 -->
<swiper class="swiper-container">
    <!-- 第一个轮播图 -->
    <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>
/* 轮播图样式 */
.swiper-container {
    height: 150px;
}

.item {
    height: 100%;
    line-height: 150px;
    text-align: center;
}

swiper-item:nth-child(1) {
    background-color: red;
}
swiper-item:nth-child(2) {
    background-color: royalblue;
}
swiper-item:nth-child(3) {
    background-color: seagreen;
}

2.4.swiper 组件的常用属性

这里放个图

3.常用的基础内容组件

text
文本组件
类似于 HTML 中的 span 标签,是一个行内元素
rich-text
富文本组件
支持把 HTML 字符串渲染为 WXML 结构

3.1.text组件的基本使用

通过text组件的selectable属性,实现长按选中文本内容的效果:
在这里插入图片描述

<view>
    手机号支持长按选中效果
    <text selectable>12378126812548172</text>
</view>

3.2.rich-text 组件的基本使用

通过 rich-text 组件的 nodes属性节点,把HTML字符串渲染为对应的UI结构:
常用于渲染来自后端的html文件

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

4.其它常用组件

button
按钮组件
功能比HTML中的 button 按钮丰富
通过 open-type 属性可以调用微信提供的各种功能(客服、转发、获取用户授权、获取用户信息等)
image
图片组件
image组件默认宽度约 300px、高度约 240px
navigator
页面导航组件
类似于 HTML 中的 a 链接

4.1.button的基本使用

在这里插入图片描述

<!-- 按钮组件的基本使用 -->
<!-- 通过 type 属性指定按钮颜色类型 -->
<button>按钮</button>
<button type="primary">主色调按钮</button>
<button type="warn">警告按钮</button>


<!-- size = "mini" 小尺寸按钮-->
<button size = "mini">按钮</button>
<button type="primary" size = "mini">主色调按钮</button>
<button type="warn" size = "mini">警告按钮</button>


<!-- plain 镂空按钮 -->
<button size = "mini" plain>按钮</button>
<button type="primary" size = "mini" plain>主色调按钮</button>
<button type="warn" size = "mini" plain>警告按钮</button>
4.2.image 组件的基本使用
<!-- image 图片组件 -->
<image></image>
<image src="/images/0.0485406259803467.jpg" mode="widthFix" alt=""/>

image 组件的 mode 属性
在这里插入图片描述

5.API

5.1.小程序API概述

小程序中的API是由宿主环境提供的,通过这些丰富的小程序API,开发者可以方便的调用微信提供的能力,
例如:获取用户信息、本地存储、支付功能等。

5.2.小程序API的3大分类

小程序官方把API分为了如下 3 大类:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值