当前位置:网站首页>【微信小程序】常用组件基本使用(view/scroll-view/swiper、text/rich-text、button/image)
【微信小程序】常用组件基本使用(view/scroll-view/swiper、text/rich-text、button/image)
2022-06-30 15:48:00 【苏凉.py】
作者简介:苏凉(专注于网络爬虫,数据分析,正在学习前端的路上)
博客主页:苏凉.py的博客
系列专栏:小程序开发基础教程
名言警句:海阔凭鱼跃,天高任鸟飞。
要是觉得博主文章写的不错的话,还望大家三连支持一下呀!!!
关注点赞收藏
文章目录
每日推荐
给大家推荐一款神器。无论你是学生党还是上班族都可以使用,这里涵盖了面试题库,在线刷题,各个大厂的面试/笔试真题等。如果你还是学生,最重要的一点就是模拟面试功能,智能AI1v1面试,帮助你早日拿到大厂offer!点击链接即可直达!=>牛客网-找工作神器
常用的视图容器类组件
view
普通视图区域,类似于HTML中的div,是一个块级元素常用来实现页面的布局效果。
WXML代码:
WXSS代码:
实现效果:

Flex布局传送门:【小程序】&【web前端】必备-Flex布局详解(弹性盒子)
scroll-view(滚动)
可滚动的视图区域,常用来实现滚动列表效果。
添加属性 scroll-y,即为纵向滚动。scroll-x,即为横向滚动。
WXML代码:
WXSS代码:
实现效果:
swiper和swiper-item(轮播图)
轮播图容器组件,轮播图item组件
swiper组件的常用属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
indicator-dots | boolean | false | 是否显示面板指示点 |
indicator-color | color | rgba(0,0,0,3) | 指示点颜色 |
indicator-active-color | color | #000000 | 当前选中的指示点颜色 |
autoplay | boolean | false | 是否自动切换 |
interval | number | 5000 | 自动切换时间间隔 |
circular | boolean | false | 是否采用衔接滑动 |
WXML代码:
WXSS代码:
实现效果:
常用的基础内容组件
text
文本组件,类似于HTML中的span标签,是一个行内元素。
使用text组件并添加selectable属性可以实现长按选中的效果。
WXML代码:
实现效果:
rich-text
富文本组件,支持把HTML字符串渲染为WXML结构。
通过rich-text组件的nodes属性节点,把 HTML字符串渲染为对应的UI结构。
WXML代码:
实现效果:
其他常用组件
button
按钮组件,功能比HTML中的button按钮丰富,通过open-type属性可以调用微信提供的各种功能(客服、转发、获取用户授权、获取用户信息等)
三种按钮样式
普通按钮/主色调按钮/警告按钮,默认自动换行
样式:
小按钮(mini)
设置size="mini"即可,设置之后不换行
样式:
镂空按钮(plain)
去除背景色。添加plain属性即可。
样式:
image
图片组件,image 组件默认宽度约300px、高度约240px
通过src属性添加图片地址:

image的mode属性
| mode值 | 说明 |
|---|---|
scaleToFill | (默认值)缩放模式,不保持纵横比缩放图片,使图片的宽高完全拉伸至填满image元素 |
aspectFit | 缩放模式,保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来。 |
aspectFill | 缩放模式,保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取。 |
widthFix | 缩放模式,宽度不变,高度自动变化,保持原图宽高比不变 |
heightFix | 缩放模式,高度不变,宽度自动变化,保持原图宽高比不变 |
下面我们来看看效果:
- scaleToFill

- aspectFill

- aspectFit

- widthFix

- heightFix

到这里我们在小程序中常用的基础组件就介绍完了,欢迎订阅本专栏,持续更新中…
更多题库和知识点总结,面试技巧请看=>牛客网,快来和我一起刷题吧!
边栏推荐
- Halcon knowledge: regional topics [07]
- MySQL proxy middleware atlas installation and configuration
- 云化XR,如何助力产业升级
- Mysql8.0 method and steps for enabling remote connection permission
- Table responsive layout tips for super nice
- Li Zexiang, a legendary Chinese professor, is making unicorns in batches
- 大学生研究生毕业找工作,该选择哪个方向?
- Yunhe enmo won the bid for Oracle maintenance project of Tianjin Binhai rural commercial bank in 2022-2023
- The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
- Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold
猜你喜欢

RT-Thread 堆區大小設置

ArcMap operation series: 80 plane to latitude and longitude 84

【牛客网刷题系列 之 Verilog快速入门】~ 位拆分与运算

备战数学建模34-BP神经网络预测2

JS ES5也可以创建常量?

荣盛生物冲刺科创板:拟募资12.5亿 年营收2.6亿

What is XR extended reality and what are the XR cloud streaming platforms
Two methods for MySQL to open remote connection permission

24:第三章:开发通行证服务:7:自定义异常(来表征程序中出现的错误);创建GraceExceptionHandler来全局统一处理异常(根据异常信息,构建对应的API统一返回对象的,JSON数据);

云技能提升好伙伴,亚马逊云师兄今天正式营业
随机推荐
什么是XR扩展现实,XR云串流平台有哪些
mysql主从配置
Rongsheng biology rushes to the scientific innovation board: it plans to raise 1.25 billion yuan, with an annual revenue of 260million yuan
Headhunter 50, 000, I'll go to VC
Raft介绍
Unsupported major. minor version 52.0
Log4j2 advanced use
[Verilog quick start of Niuke online question series] ~ bit splitting and operation
今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
[cve-2019-0193] - Apache Solr dataimport remote command execution analysis
Cesium-1.72 learning (add points, lines, cubes, etc.)
新茶饮“死去活来”,供应商却“盆满钵满”?
云化XR,如何助力产业升级
halcon知识:区域专题【07】
What is the difference between real-time rendering and pre rendering
[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!
Implementation of Devops in the core field of qunar, the Internet R & D Efficiency
19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
360 digital, ant group, etc. were selected as member units of the "business security promotion plan" of the Chinese Academy of Communications
Niuke.com: minimum cost of climbing stairs
