amis2/docs/zh-CN/components/search-box.md

581 lines
13 KiB
Markdown
Raw Permalink Normal View History

2021-04-23 11:39:32 +08:00
---
2021-04-25 17:49:29 +08:00
title: Search Box 搜索框
2021-04-23 11:39:32 +08:00
description:
type: 0
group: ⚙ 组件
menuName: Search Box
icon:
---
## 基本用法
用于展示一个简单搜索框,通常需要搭配其他组件使用。比如 page 配置 `initApi` 后,可以用来实现简单数据过滤查找,`name` keywords 会作为参数传递给 page 的 `initApi`
```schema
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
2021-04-23 11:39:32 +08:00
"body": [
{
"type": "search-box",
"name": "keywords"
},
style:cxd主题对齐云舍4.0样式 (#4354) * Select Options等组件样式对齐4.0 * 更新测试快照 * 修改部分测试用例 * feat:4.0样式修改 * 修改checkboxes hover问题 * Feat image 4.0 (#4242) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * fix: textarea组件对齐4.0标准 (#4149) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * fix: inputTree 组价对齐4.0标准 (#4148) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: inputTree组件对齐4.0标准 * fix: inputtree组件图标颜色修改 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * feat: 部分组件样式问题修复 (#4154) * feat: input-text 样式 * feat: input-range 样式 * feat: table 样式 1 * feat: search-box * feat: curd icon * feat: table 空状态 * feat: input-text 多选,最大宽度设置 * feat: search-box 搜索图标颜色 * feat: crud 编辑、过滤、搜索、排序 图标样式修改 * feat: 更新快照 * feat: 更新快照 2 * feat: curd fix * feat: curd edit icon fix * feat: input-password 不可见 icon 修改 * feat: input-password snapshot update * docs:完善对话框size参数说明 * feat: Log 组件支持虚拟渲染及限制最大行数 * 修复不支持 loading 问题 * 换一下名字 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> Co-authored-by: liweijian <liweijian@hkmtl.com> Co-authored-by: wuduoyi <wuduoyi@baidu.com> Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> * fix:修复删除图标颜色问题 (#4245) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: 修复conditionbuilder组价图标颜色问题 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * form表单对齐云社4.0 (#4248) * feat: form增加表单项 label文本对齐方式选项 * fix: remark 支持在表单内配置 * style: form 间距对齐云社4.0 Co-authored-by: sarding <hongfuquan@baidu.com> * Fix chart radios name (#4251) * fix: Chart 单选框 修改为 ChartRadios 图表单选框 * fix: input-password 修改 可见 图标 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * feat: checkboxes内边距&nestedSelect箭头修改 (#4254) Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * Feature style 4.0 cxd (#4261) * feat: 日期&折叠面板&提示样式对齐 * fix:测试用例修复 * feat: timeRange开始和结束分开&日期样式优化 * styles: 日历样式修复 Co-authored-by: hongyang03 <hongyang03@baidu.com> * 整体字体大小调整 (#4264) * feat: form增加表单项 label文本对齐方式选项 * fix: remark 支持在表单内配置 * style: form 间距对齐云社4.0 * 修改表单的字体 Co-authored-by: sarding <hongfuquan@baidu.com> * inputfile 和 drawer对齐云社4.0 (#4249) * fix: drawer 和 inputfile 关闭图标对齐云社4.0 * fix:修改 drawer的图标大小 和边框圆角 * drawer 样式调整 Co-authored-by: sarding <hongfuquan@baidu.com> * Fix style (#4265) * fix: input-password icon 高度 * fix: input-password icon 换行问题 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * fix: curd 图标垂直居中 (#4271) Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * fix:修复nestedSelect无法动态调整位置及溢出问题 (#4292) Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * style: 优化switch组件动效 (#4302) * style:优化date组件最小宽度 (#4303) * style:cxd主题移动端基础字号调整为16px (#4305) * style:switch调整动效速度 * chore:更新快照 * chore:更新快照 Co-authored-by: xujiahao01 <xujiahao01@baidu.com> Co-authored-by: qiaogg <43558337+qiaogg@users.noreply.github.com> Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> Co-authored-by: sansiro <sansiro@sansiro.me> Co-authored-by: liuzedong02 <liuzedong02@baidu.com> Co-authored-by: liweijian <liweijian@hkmtl.com> Co-authored-by: wuduoyi <wuduoyi@baidu.com> Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Co-authored-by: sarding <37691952+sarding@users.noreply.github.com> Co-authored-by: sarding <hongfuquan@baidu.com> Co-authored-by: 徐佳豪 <53201551+blue-squirrel@users.noreply.github.com> Co-authored-by: HongYang <33488114+hy993658052@users.noreply.github.com> Co-authored-by: hongyang03 <hongyang03@baidu.com>
2022-05-18 10:03:56 +08:00
{
"type": "tpl",
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
}
]
}
```
## 禁用样式
> `6.0.0`及以上版本
```schema
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "flex",
"direction": "column",
"justify": "flex-start",
"alignItems": "flex-start",
"items": [
{
"type": "search-box",
"name": "keywords",
"disabled": true,
"style": {
"marginBottom": "10px"
}
},
{
"type": "search-box",
"name": "keywords",
"mini": true,
"disabled": true
}
]
}
]
}
```
## 加载状态
> `6.0.0` 及以上版本
设置`"loading": true`, 标识开关操作的异步任务仍在执行中。另外`loadingOn`支持表达式,配合`ajax`动作实现搜索操作时的loading状态。
```schema
{
"type": "page",
"id": "demo-page",
"data": {
"isFetching": false,
"fetched": false
},
"body": [
{
"type": "search-box",
"name": "keywords",
"clearable": true,
"loadingOn": "${isFetching}",
"className": "mb-2",
"onEvent": {
"search": {
"actions": [
{
"actionType": "setValue",
"componentId": "demo-page",
"args": {
"value": {
"isFetching": true
}
}
},
{
"actionType": "toast",
"args": {
"msgType": "warning",
"msg": "开始检索..."
}
},
{
"actionType": "ajax",
"api": {
"url": "/api/mock2/sample?perPage=5&waitSeconds=2&keywords=${keywords}",
"method": "get",
"messages": {
"success": "检索完成",
"failed": "检索失败"
}
}
},
{
"actionType": "setValue",
"componentId": "demo-page",
"args": {
"value": {
"isFetching": false,
"fetched": true,
"total": "${event.data.responseResult.count}",
"datasource": "${event.data.responseResult.rows}"
}
}
}
]
}
}
},
{
"type": "flex",
"visibleOn": "${fetched && !isFetching}",
"justify": "flex-start",
"alignItems": "flex-start",
"direction": "column",
"items": [
{
"type": "flex",
"className": "mb-2",
"alignItems": "self-end",
"items": [
{
"type": "status",
"value": "success",
"className": "mr-2",
"labelMap": {
"success": "检索成功:"
}
},
{
"type": "tpl",
"tpl": "总计${total}条当前仅展示5条"
},
]
},
{
"type": "list",
"source": "${datasource}",
"listItem": {
"body": [
{
"type": "hbox",
"columns": [
{
"label": "Engine",
"name": "engine"
},
{
"name": "version",
"label": "Version"
}
]
}
]
}
}
]
}
]
}
```
style:cxd主题对齐云舍4.0样式 (#4354) * Select Options等组件样式对齐4.0 * 更新测试快照 * 修改部分测试用例 * feat:4.0样式修改 * 修改checkboxes hover问题 * Feat image 4.0 (#4242) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * fix: textarea组件对齐4.0标准 (#4149) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * fix: inputTree 组价对齐4.0标准 (#4148) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: inputTree组件对齐4.0标准 * fix: inputtree组件图标颜色修改 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * feat: 部分组件样式问题修复 (#4154) * feat: input-text 样式 * feat: input-range 样式 * feat: table 样式 1 * feat: search-box * feat: curd icon * feat: table 空状态 * feat: input-text 多选,最大宽度设置 * feat: search-box 搜索图标颜色 * feat: crud 编辑、过滤、搜索、排序 图标样式修改 * feat: 更新快照 * feat: 更新快照 2 * feat: curd fix * feat: curd edit icon fix * feat: input-password 不可见 icon 修改 * feat: input-password snapshot update * docs:完善对话框size参数说明 * feat: Log 组件支持虚拟渲染及限制最大行数 * 修复不支持 loading 问题 * 换一下名字 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> Co-authored-by: liweijian <liweijian@hkmtl.com> Co-authored-by: wuduoyi <wuduoyi@baidu.com> Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> * fix:修复删除图标颜色问题 (#4245) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: 修复conditionbuilder组价图标颜色问题 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * form表单对齐云社4.0 (#4248) * feat: form增加表单项 label文本对齐方式选项 * fix: remark 支持在表单内配置 * style: form 间距对齐云社4.0 Co-authored-by: sarding <hongfuquan@baidu.com> * Fix chart radios name (#4251) * fix: Chart 单选框 修改为 ChartRadios 图表单选框 * fix: input-password 修改 可见 图标 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * feat: checkboxes内边距&nestedSelect箭头修改 (#4254) Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * Feature style 4.0 cxd (#4261) * feat: 日期&折叠面板&提示样式对齐 * fix:测试用例修复 * feat: timeRange开始和结束分开&日期样式优化 * styles: 日历样式修复 Co-authored-by: hongyang03 <hongyang03@baidu.com> * 整体字体大小调整 (#4264) * feat: form增加表单项 label文本对齐方式选项 * fix: remark 支持在表单内配置 * style: form 间距对齐云社4.0 * 修改表单的字体 Co-authored-by: sarding <hongfuquan@baidu.com> * inputfile 和 drawer对齐云社4.0 (#4249) * fix: drawer 和 inputfile 关闭图标对齐云社4.0 * fix:修改 drawer的图标大小 和边框圆角 * drawer 样式调整 Co-authored-by: sarding <hongfuquan@baidu.com> * Fix style (#4265) * fix: input-password icon 高度 * fix: input-password icon 换行问题 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * fix: curd 图标垂直居中 (#4271) Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * fix:修复nestedSelect无法动态调整位置及溢出问题 (#4292) Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * style: 优化switch组件动效 (#4302) * style:优化date组件最小宽度 (#4303) * style:cxd主题移动端基础字号调整为16px (#4305) * style:switch调整动效速度 * chore:更新快照 * chore:更新快照 Co-authored-by: xujiahao01 <xujiahao01@baidu.com> Co-authored-by: qiaogg <43558337+qiaogg@users.noreply.github.com> Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> Co-authored-by: sansiro <sansiro@sansiro.me> Co-authored-by: liuzedong02 <liuzedong02@baidu.com> Co-authored-by: liweijian <liweijian@hkmtl.com> Co-authored-by: wuduoyi <wuduoyi@baidu.com> Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Co-authored-by: sarding <37691952+sarding@users.noreply.github.com> Co-authored-by: sarding <hongfuquan@baidu.com> Co-authored-by: 徐佳豪 <53201551+blue-squirrel@users.noreply.github.com> Co-authored-by: HongYang <33488114+hy993658052@users.noreply.github.com> Co-authored-by: hongyang03 <hongyang03@baidu.com>
2022-05-18 10:03:56 +08:00
## 加强样式
```schema
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"enhance": true
},
{
"type": "tpl",
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
}
]
}
```
## 可清除
```schema
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"clearable": true
},
2021-04-23 11:39:32 +08:00
{
"type": "tpl",
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
}
]
}
```
### 清除后立即搜索
2023-02-27 21:39:28 +08:00
> `2.8.0` 及以上版本
设置`"clearAndSubmit": true`后,清空搜索框内容后立即执行搜索,与`searchImediately`不同的是,`clearAndSubmit`仅作用于清空输入框的动作,而`searchImediately`会影响所有搜索动作。
```schema
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"clearable": true,
"clearAndSubmit": true
},
{
"type": "tpl",
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
}
]
}
```
2021-04-23 11:39:32 +08:00
## mini 版本
```schema
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
2021-04-23 11:39:32 +08:00
"body": [
{
"type": "search-box",
"name": "keywords",
"mini": true
},
{
"type": "tpl",
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
}
]
}
```
## 与 CRUD 搭配
```schema: scope="body"
{
"type": "crud",
"api": "/api/mock2/sample",
2021-04-23 11:39:32 +08:00
"syncLocation": false,
"headerToolbar": [
{
"type": "search-box",
"name": "keywords",
"align": "right",
"placeholder": "关键字检索"
}
],
"columns": [
{
"name": "id",
"label": "ID"
},
{
"name": "engine",
"label": "Rendering engine"
},
{
"name": "browser",
"label": "Browser"
},
{
"name": "platform",
"label": "Platform(s)"
},
{
"name": "version",
"label": "Engine version"
},
{
"name": "grade",
"label": "CSS grade"
}
]
}
```
## 与 Service 搭配
```schema
{
"type": "page",
"body": [
{
"type": "service",
"api": "/api/mock2/page/initData?keywords=${keywords}",
2021-04-23 11:39:32 +08:00
"body": [
{
"type": "search-box",
"name": "keywords"
},
{
"type": "tpl",
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
}
]
}
]
}
```
## 立刻搜索模式
设置 `"searchImediately": true` 实现输入时即搜索
```schema
{
"type": "page",
"body": [
{
"type": "service",
"api": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"searchImediately": true
},
{
"type": "tpl",
"tpl": "<p>关键字:${keywords}</p><p>返回结果:${&|json}</p>"
}
]
}
]
}
```
2021-04-23 11:39:32 +08:00
## 属性表
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ---------------- | --------- | ------ | ---------------------------- | ------- |
| type | `string` | | `search-box` |
| className | `string` | | 外层 CSS 类名 |
| mini | `boolean` | | 是否为 mini 模式 |
| searchImediately | `boolean` | | 是否立即搜索 |
2023-02-27 21:39:28 +08:00
| clearAndSubmit | `boolean` | | 清空搜索框内容后立即执行搜索 | `2.8.0` |
| disabled | `boolean` | `false` | 是否为禁用状态 | `6.0.0` |
| loading | `boolean` | `false` | 是否处于加载状态 | `6.0.0` |
2022-11-14 11:38:44 +08:00
## 事件表
> 2.4.1 及以上版本
2023-05-28 22:26:48 +08:00
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
2022-11-14 11:38:44 +08:00
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------- |
| search | `[name]: string` 组件的值 | 点击搜索图标时触发 |
| change | `[name]: string` 组件的值 | 输入框值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点时触发 |
2023-05-28 22:26:48 +08:00
### search
```schema
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"onEvent": {
"search": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${keywords}"
}
}
]
}
}
}
]
}
```
### change
```schema: scope="body"
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${keywords}"
}
}
]
}
}
}
]
}
```
### focus
```schema: scope="body"
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"onEvent": {
"focus": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${keywords}"
}
}
]
}
}
}
]
}
```
### blur
```schema: scope="body"
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"onEvent": {
"blur": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${keywords}"
}
}
]
}
}
}
]
}
```
2022-11-14 11:38:44 +08:00
## 动作表
> 2.4.1 及以上版本
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | -------- |
| clear | - | 清空 |
| setValue | `value: string` 更新的值 | 更新数据 |
2023-05-28 22:26:48 +08:00
### clear
```schema: scope="body"
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"id": "s01"
},
{
"type": "button",
"label": "清除",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "s01"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "page",
"initApi": "/api/mock2/page/initData?keywords=${keywords}",
"body": [
{
"type": "search-box",
"name": "keywords",
"id": "s02"
},
{
"type": "button",
"label": "设置关键字",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "s02",
"args": {
"value": "amis"
}
}
]
}
}
}
]
}
```