文章插图
文章插图
?
代码如下:
index.wxml:
<view class="container"><view><form catchsubmit="formSubmit" catchreset="formReset"><text>AGC-function-Demo</text><text>\n</text><text>\n</text><view class="weui-cell__bd" style="margin: 30rpx 0"><input class="weui-input" name="httpTrigger" placeholder="input your HttpTrigger" /></view><view class="weui-cell__bd" style="margin: 30rpx 0"><input class="weui-input" name="body" placeholder="input your Body" /></view><text>\n</text><view class="btn-area"><button style="margin: 30rpx 0" type="primary" formType="submit" data-type="run">run</button></view></form></view><view class="text-box"><text class="text-content">{{functionRes}}</text></view></view>
文章插图
文章插图
index.wxss:
/**index.wxss**/.container {padding: 0 0;}.userinfo {color: #aaa;}.userinfo-avatar {overflow: hidden;width: 128rpx;height: 128rpx;margin: 20rpx;border-radius: 50%;}.section_switch {display: flex;align-items: center;justify-content: space-around;}.text-box {margin: 20rpx;}.text-content {word-break: break-all;}
文章插图
文章插图
云函数开发云函数最主要的功能就是在端侧触发云测的函数,首先调用wrap接口通过触发器标识指定需要触发的函数,然后调用call接口将函数的入参传入并触发函数 。
formSubmit: function (e) {console.log(e);var _a = e.detail.value, httpTrigger = _a.httpTrigger, body = _a.body;switch (e.detail.target.dataset.type) {case 'run':this.run(httpTrigger, body);break;default:break;}},run: function (httpTrigger, body) {var _this = this;var functionCallable = agconnect.function().wrap(httpTrigger);functionCallable.call(body).then(function (res) {_this.setData({functionRes: JSON.stringify(res.getValue())});});}
文章插图
文章插图
在初始化时输入刚刚复制的应用配置信息
var agConnectConfig = {//应用配置信息}//初始化agcagconnect.instance().configInstance(agConnectConfig);
文章插图
文章插图
打包测试1.打开微信开发者工具 , 选择编译 。
2. 打开页面后再HttpTrigger中填写之前在创建触发器时获取的触发器标识,再Function Body中添加触发的入参 。
文章插图
文章插图
?
3.点击run后查看result 。
打印结果显示2022是虎年,说明测试成功
文章插图
文章插图
?
恭喜您祝贺您 , 您已经成功地构建了您的第一个应用程序,并学到了:
- 如何将方法函数添加为AppGallery Connect的云函数 。
- 如何测试添加的云函数 。
- 如何集成AppGallery Connect云函数的SDK并在本地调用云函数 。
- 详细的云函数配置开发指南请参见云函数服务开发指南 。
- 云函数的相关API介绍请参见云函数API参考 。
推荐阅读
- ipad分屏怎么打开(ipad第九代可以分屏吗)
- 苹果ipad分屏功能怎么使用(ipad微信分屏怎么取消)
- vivox60参数配置详情_vivox60手机配置
- .NET周报【10月第3期 2022-10-25】
- 【vue2】Style和Class,条件,列表渲染,双向数据绑定,事件处理
- HDFS追加数据报错解决办法
- 微信绑定账号怎么解除(一键解除绑定手机号)
- 三 【单片机入门】应用层软件开发的单片机学习之路-----UART串口通讯和c#交互
- 英雄联盟手游战利品系统该怎么玩
- 支付宝庄园小课堂答案9.21