线索通 sdk 字节小程序网络请求插件
能力
发起网络请求
初始化
需要配合 @clue_nidapp/form-core
线索通 sdk 使用
初始化线索通 SDK,详见 @clue_nidapp/form-core
使用说明
import { Core, FormOptions } from '@clue_nidapp/form-core/web';
import { API } from '@clue_nidapp/plugin-api-mini'
const options: FormOptions = {
data: {
formId: 0,
advId: 0,
clueAccountId: 0,
},
externalSetting: {
scenarioType: 23,
isExternalOpenLink: true,
}
// 注册插件
plugins: [new API()]
}
const formCore = new Core(
options,
);
支持环境
字节小程序
使用
注册后,sdk 会自动将 request 方法挂载到 Core 实例 request 方法上
目前支持 get
和 post
方法
interface Request {
get: (
url: string, // 请求 url
data: object, // 请求体
options: Options
) => Promise<any>;
post: (
url: string, // 请求 url
data: object, // 请求体
options: Options
) => Promise<any>;
}
请求参数 options 详细说明
interface Options {
timeout: number; // 超时时间,单位为毫秒
cache: boolean; // 开启 cache 默认为 false
}
formCore.request.get(url, data, options).then((res) => {
// do something with res
});
formCore.request.post(url, data, options).then((res) => {
// do something with res
});