AMIS中写一个自动触发的配置下发触发器
时间: 2023-11-05 22:06:44 浏览: 44
在 AMIS 中,可以使用 `Trigger` 组件来实现自动触发的配置下发。具体步骤如下:
1. 在 `schema` 中定义触发器的配置项,例如:
```json
{
"type": "object",
"properties": {
"autoTrigger": {
"type": "boolean",
"title": "自动触发",
"default": false
}
}
}
```
2. 在 `page` 中定义触发器组件,例如:
```json
{
"type": "page",
"body": [
{
"type": "trigger",
"name": "autoTrigger",
"target": "api://myApi",
"condition": "{{formData.autoTrigger}}"
}
]
}
```
其中,`name` 表示触发器的名称,`target` 表示触发器要触发的接口,`condition` 表示触发器的触发条件,这里使用了 `formData.autoTrigger`,表示当表单中的 `autoTrigger` 字段为 `true` 时触发器才会执行。
3. 在 `api` 中定义触发器要触发的接口,例如:
```json
{
"type": "api",
"name": "myApi",
"method": "post",
"url": "/api/myApi",
"data": "{{formData}}"
}
```
其中,`data` 表示要传递给接口的数据,这里使用了 `formData`,即表单中的所有数据。
这样,在页面中设置 `autoTrigger` 字段为 `true` 后,触发器就会自动触发 `myApi` 接口,并将表单数据作为参数传递给接口。