invoke
invoke
api是可以让前端应用访问后端的函数。
要使用 invoke
,需要先使用resolver定义函数,参考 自定义UI Resolver
可以参考demo: invoke
使用
在Custom UI 的前端代码中引入@giteeteam/plugin-sdk
import { invoke } from '@giteeteam/plugin-sdk';
const Demo = () => {
useEffect(() => {
const payload = {
example: 'hello'
}
const result = await invoke("method-key", payload); // payload 是执行参数
console.log(result) // 返回的数据
},[])
return <div></div>
}
函数声明
function invoke(
methodKey: string,
payload?: { [key in number | string]: any }
): Promise<{ [key: string]: any } | void>;
参数说明
- methodKey: 对应resolver中define的methodKey
- payload: 传给resolver的数据