企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件 同普通的HTML不一样,小程序内置一些组件,用法跟HTML标签相似。 ## 什么是组件 - 组件是视图层的基本组成单元。 - 组件自带一些功能与微信风格的样式。 - 一个组件通常包括开始标签和结束标签,属性用来修饰这个组件,内容在两个标签之内。 ```html <tagname property="value"> Content goes here ... </tagname> ``` ## 基础组件 ## 属性类型 | 类型 | 描述 | 注解 | | ------------ | ------- | ---------------------------------------- | | Boolean | 布尔值 | 组件写上该属性,不管该属性等于什么,其值都为`true`,只有组件上没有写该属性时,属性值才为`false`。如果属性值为变量,变量的值会被转换为Boolean类型 | | Number | 数字 | `1`, `2.5` | | String | 字符串 | `"string"` | | Array | 数组 | `[ 1, "string" ]` | | Object | 对象 | `{ key: value }` | | EventHandler | 事件处理函数名 | `"handlerName"` 是 [Page](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/app-service/page.html)中定义的事件处理函数名 | | Any | 任意属性 | | ## 共同属性类型 所有组件都有的属性: | 属性名 | 类型 | 描述 | 注解 | | -------------- | ------------ | ------- | ---------------------------------------- | | id | String | 组件的唯一标示 | 保持整个页面唯一 | | class | String | 组件的样式类 | 在对应的 WXSS 中定义的样式类 | | style | String | 组件的内联样式 | 可以动态设置的内联样式 | | hidden | Boolean | 组件是否显示 | 所有组件默认显示 | | data-* | Any | 自定义属性 | 组件上触发的事件时,会发送给事件处理函数 | | bind* / catch* | EventHandler | 组件的事件 | 详见[事件](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxml/event.html) | ## 特殊属性 几乎所有组件都有各自定义的属性,可以对该组件的功能或样式进行修饰,请参考各个[组件](https://mp.weixin.qq.com/debug/wxadoc/dev/component/#%E7%BB%84%E4%BB%B6%E5%88%97%E8%A1%A8)的定义。 ## 组件分类 基础组件分为以下七大类: ### **视图容器(View Container):** | 组件名 | 说明 | | ---------------------------------------- | ------- | | [view](https://mp.weixin.qq.com/debug/wxadoc/dev/component/view.html) | 视图容器 | | [scroll-view](https://mp.weixin.qq.com/debug/wxadoc/dev/component/scroll-view.html) | 可滚动视图容器 | | [swiper](https://mp.weixin.qq.com/debug/wxadoc/dev/component/swiper.html) | 滑块视图容器 | ### **基础内容(Basic Content):** | 组件名 | 说明 | | ---------------------------------------- | ---- | | [icon](https://mp.weixin.qq.com/debug/wxadoc/dev/component/icon.html) | 图标 | | [text](https://mp.weixin.qq.com/debug/wxadoc/dev/component/text.html) | 文字 | | [progress](https://mp.weixin.qq.com/debug/wxadoc/dev/component/progress.html) | 进度条 | ### **表单(Form):** | 标签名 | 说明 | | ---------------------------------------- | ------- | | [button](https://mp.weixin.qq.com/debug/wxadoc/dev/component/button.html) | 按钮 | | [form](https://mp.weixin.qq.com/debug/wxadoc/dev/component/form.html) | 表单 | | [input](https://mp.weixin.qq.com/debug/wxadoc/dev/component/input.html) | 输入框 | | [checkbox](https://mp.weixin.qq.com/debug/wxadoc/dev/component/checkbox.html) | 多项选择器 | | [radio](https://mp.weixin.qq.com/debug/wxadoc/dev/component/radio.html) | 单项选择器 | | [picker](https://mp.weixin.qq.com/debug/wxadoc/dev/component/picker.html) | 列表选择器 | | [picker-view](https://mp.weixin.qq.com/debug/wxadoc/dev/component/picker-view.html) | 内嵌列表选择器 | | [slider](https://mp.weixin.qq.com/debug/wxadoc/dev/component/slider.html) | 滚动选择器 | | [switch](https://mp.weixin.qq.com/debug/wxadoc/dev/component/switch.html) | 开关选择器 | | [label](https://mp.weixin.qq.com/debug/wxadoc/dev/component/label.html) | 标签 | ### **导航(Navigation):** | 组件名 | 说明 | | ---------------------------------------- | ---- | | [navigator](https://mp.weixin.qq.com/debug/wxadoc/dev/component/navigator.html) | 应用链接 | ### **多媒体(Media):** | 组件名 | 说明 | | ---------------------------------------- | ---- | | [audio](https://mp.weixin.qq.com/debug/wxadoc/dev/component/audio.html) | 音频 | | [image](https://mp.weixin.qq.com/debug/wxadoc/dev/component/image.html) | 图片 | | [video](https://mp.weixin.qq.com/debug/wxadoc/dev/component/video.html) | 视频 | ### **地图(Map):** | 组件名 | 说明 | | ---------------------------------------- | ---- | | [map](https://mp.weixin.qq.com/debug/wxadoc/dev/component/map.html) | 地图 | ### **画布(Canvas):** | 组件名 | 说明 | | ---------------------------------------- | ---- | | [canvas](https://mp.weixin.qq.com/debug/wxadoc/dev/component/canvas.html) | 画布 |