发布时间:2026/8/6 18:35:38
amis调用接口的几种常见方式 一、serviceamis - 低代码前端框架-servicehttps://aisuda.bce.baidu.com/amis/zh-CN/components/service使用场景:1.需要在form组件中单独处理保存接口2.需要存储变量给页面使用{ type: button, label: 新增, actionType: dialog, dialog: { body: { type: form, debug: true, api: { url: /amis/api/mock2/form/saveForm, method: POST, data: { query_no: ${query_no-01} } }, body: [ { id: service-1, type: service, api: { url: /amis/api/mock2/options/chainedOptions?waitSeconds1parentId$parentIdlevel$levelmaxLevel4, method: GET, responseData: { options: ${items|pick:index,value,label} } }, initFetch: false, body: { name: query_no, type: hidden, label: 前一个编号, required: true, value: ${options[options.length-1].index} } } ] }, actions: [ { type: button, label: 保存, onEvent: { click: { actions: [ { actionType: reload, componentId: service-1 } ] } } } ] } }二、ajaxamis - 低代码前端框架-发送-http-请求https://aisuda.bce.baidu.com/amis/zh-CN/docs/concepts/event-action#%E5%8F%91%E9%80%81-http-%E8%AF%B7%E6%B1%82amis - 低代码前端框架-Action行为按钮https://aisuda.bce.baidu.com/amis/zh-CN/components/action#ajax-%E8%AF%B7%E6%B1%82使用场景不需要校验输入框错误信息就直接调用接口的场景比如期望保存接口和提交接口分开处理代码示例{ type: page, data: { name: lll, id: 222 }, body: [ { type: button, id: b_001, label: 发送 Ajax 请求, level: primary, confirmText: 确认要发出这个请求, onEvent: { click: { actions: [ { actionType: ajax, args: { api: { url: /amis/api/mock2/form/saveForm?name${name}, method: post, data: { resId: ${id} }, messages: { success: 成功了欧耶, failed: 失败了呢。。 } } } } ] } } } ] }简化1{ type: page, data: { name: lll, id: 222 }, body: [ { type: button, id: b_001, label: 发送 Ajax 请求, level: primary, confirmText: 确认要发出这个请求, onEvent: { click: { actions: [ { actionType: ajax, api: { url: /amis/api/mock2/form/saveForm?name${name}, method: post, data: { resId: ${id} }, messages: { success: 成功了欧耶, failed: 失败了呢。。 } } } ] } } } ] }简写2{ type: page, data: { name: lll, id: 222 }, body: [ { type: button, id: b_001, label: 发送 Ajax 请求, level: primary, confirmText: 确认要发出这个请求, actionType: ajax, api: { url: /amis/api/mock2/form/saveForm?name${name}, method: post, data: { resId: ${id} }, messages: { success: 成功了欧耶, failed: 失败了呢。。 } } } } ] }三、custom XMLHttpRequestamis - 低代码前端框架-自定义jshttps://aisuda.bce.baidu.com/amis/zh-CN/docs/concepts/event-action#%E8%87%AA%E5%AE%9A%E4%B9%89-jsXML HttpRequesthttps://www.w3school.com.cn/xml/xml_http.asp原生JavaScript的xhr代码示例get请求示例var xhr new XMLHttpRequest(); var params new URLSearchParams(); params.append(a, 1); params.append(b, 1); xhr.open(GET, /xxx? params.toString(), true); xhr.onreadystatechange function() { if (xhr.readyState 4) { if (xhr.status 200) { console.log(xhr.responseText); } else { console.error(请求失败:, xhr.status); } } }; xhr.send();post请求示例var xhr new XMLHttpRequest(); xhr.open(POST, /xxx, true); xhr.setRequestHeader(Content-Type, application/json); xhr.onreadystatechange function() { if (xhr.readyState 4) { if (xhr.status 200) { console.log(xhr.responseText); } else { console.error(请求失败:, xhr.status); } } }; xhr.send(JSON.stringify({ a: 1, b: 1 }));amis框架代码示例{ type: page, data: { name: lll, id: 222 }, body: [ { type: button, id: b_001, label: 发送 Ajax 请求, level: primary, confirmText: 确认要发出这个请求, onEvent: { click: { actions: [ { actionType: custom, script: const {name, id} event.data;\n\nvar xhr new XMLHttpRequest();\nxhr.open(POST, /amis/api/mock2/form/saveForm?name encodeURIComponent(name), true);\nxhr.setRequestHeader(Content-Type, application/json);\n\nxhr.onload function() {\n if (xhr.status 200 xhr.status 300) {\n var result JSON.parse(xhr.responseText);\n event.setData({ resId: result.id || id });\n\n doAction({\n actionType: toast,\n args: {\n msgType: info,\n msg: 成功了欧耶\n }\n });\n } else {\n doAction({\n actionType: toast,\n args: {\n msgType: error,\n msg: 失败了呢。。\n }\n });\n }\n};\n\nxhr.onerror function() {\n doAction({\n actionType: toast,\n args: {\n msgType: error,\n msg: 失败了呢。。\n }\n });\n};\n\nxhr.send(JSON.stringify({ resId: id })); } ] } } } ] }四、form组件使用api属性{ type: button, label: 新增, actionType: dialog, dialog: { body: { type: form, debug: true, api: { url: /amis/api/mock2/form/saveForm, method: POST, data: { query_no: ${query_no-01} } }, body: [ { type: service, api: { url: /amis/api/mock2/options/chainedOptions?waitSeconds1parentId$parentIdlevel$levelmaxLevel4, method: GET, responseData: { options: ${items|pick:index,value,label} } }, body: { name: query_no, type: hidden, label: 前一个编号, required: true, value: ${options[options.length-1].index} } } ] }, actions: [ { type: button, label: 保存, actionType: submit } ] } }

相关新闻

2026/8/6 18:30:37

ComfyUI-VideoHelperSuite终极指南:3步快速构建AI视频工作流

ComfyUI-VideoHelperSuite终极指南:3步快速构建AI视频工作流 【免费下载链接】ComfyUI-VideoHelperSuite Nodes related to video workflows 项目地址: https://gitcode.com/gh_mirrors/co/ComfyUI-VideoHelperSuite ComfyUI-VideoHelperSuite是专为AI视频创…

2026/8/6 18:30:37

[STM32]CAN总线

一:CAN简介CAN(Controller Area Network)控制器局域网总线是由博世 (Bosch) 在 1980开发的一种传输速度快、易扩展、可靠性高的串行通信总线, 现在广泛用在汽车、工业控制、嵌入式设备。补充:CAN 虽然是差分通信&#…

2026/8/6 19:35:43

零信任系统:多模式部署下的内网访问安全实践

在数字化业务持续扩张的背景下,传统基于网络边界的安全模型,已经难以应对远程办公、混合云、内外网互通带来的访问风险。零信任 “永不信任、始终验证” 的核心理念,正在成为政企、制造业保护业务资源的重要方案。本文围绕零信任系统&#xf…

2026/8/6 19:35:43

Awesome Restic完全指南:发现30+顶级备份工具与资源

Awesome Restic完全指南:发现30顶级备份工具与资源 【免费下载链接】awesome-restic Awesome Restic related projects 项目地址: https://gitcode.com/gh_mirrors/aw/awesome-restic Awesome Restic是一个精选的Restic相关项目集合,汇集了30多种…

2026/8/6 19:35:43

鲸剪 WhaleClip好用吗?5款AI小说配音工具横评

小说推文配音,到底难在哪做小说推文和有声书账号的人,大概率都卡在同一个环节:配音。以前要么自己录,要么找主播外包,单条成本低但一上量就顶不住;后来换成通用 TTS,又发现男一女一男二女二听起…

2026/8/6 19:30:41

服装店应对电商冲击:实体门店不该补的短板和该守的阵地

这两年走访了不少服装门店,听到最多的一句话是:生意不是不行了,是搞不懂客人去哪了。很多老板把原因归结为电商太便宜、直播太卷,但实际上,把时间拉长看,真正被电商冲击掉的门店,往往不是输在价…

2026/8/5 3:13:11

如何用免费工具突破游戏窗口限制:SRWE完整使用指南

如何用免费工具突破游戏窗口限制:SRWE完整使用指南 【免费下载链接】SRWE Simple Runtime Window Editor 项目地址: https://gitcode.com/gh_mirrors/sr/SRWE 你是否遇到过这样的困扰?想为心爱的游戏截图,却发现游戏不支持自定义分辨率…

2026/8/6 0:04:22

电力系统调度中的源荷不确定性建模与优化实践

1. 电力系统调度中的源荷不确定性挑战现代电力系统正面临前所未有的复杂性,其中源荷不确定性(Source-Load Uncertainty)已成为调度决策中最棘手的难题之一。我在参与某省级电网调度系统升级时,曾遇到风电预测误差导致日内调度计划…

2026/8/6 0:04:22

VGG-T3技术解析:3D重建速度的革命性突破

1. 项目概述:VGG-T3如何重新定义3D重建速度在计算机视觉领域,3D场景重建一直是个计算密集型任务。传统方法重建1000帧图像规模的场景往往需要数小时甚至更长时间,而英伟达最新发布的VGG-T3技术将这个时间压缩到了惊人的54秒。这个突破性进展来…

2026/8/6 0:04:22

深度解析旅游网站建设的意义及其对行业发展的深远影响与核心价值体现

在这个数字化浪潮席卷全球的今天,我们似乎已经忘记了,曾经有一段时间,人们想要去一个陌生的地方,只能靠在书桌前翻阅厚厚的旅游杂志,或者向刚从那里回来的朋友询问那些模糊不清的印象。那时候,“远方”是一个需要精打细算才能抵达的奢侈概念。而现在,只需要一部手机,轻…

2026/8/5 19:21:13

实测才敢推 AI论文网站 2026最新测评与推荐

2026年真正好用的AI论文网站,核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测,千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队,覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。一、综…

2026/8/5 19:21:13

2026必备!AI论文网站测评:最新推荐与深度对比

2026年真正好用的AI论文网站,核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测,千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队,覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。 一、…

2026/8/5 19:21:13

摆脱论文困扰!盘点2026年全网爆红的的AI论文写作工具

一天写完毕业论文在2026年已不再是天方夜谭。2026年最炸裂、实测能大幅提速的AI论文写作工具,覆盖选题构思、文献整理、内容生成、格式排版等核心场景,真正帮你高效搞定论文难题。 一、全流程王者:一站式搞定论文全链路(一天定稿首…