@tb-app/web-view-api
Version:
实现webview与淘宝小程序之间的通信
50 lines (49 loc) • 1.27 kB
TypeScript
/**
* 只能在 web-view 端调用,使用小程序端注册的功能
* @param options
* @returns
*/
declare function invoke(options: {
type: string;
data?: any;
}): Promise<any>;
/**
* 调用小程序my上的api, 不支持监听和创建上下文之类的api
* @param data
*/
declare function invokeMy({ type, data }: {
type: string;
data?: any;
}): Promise<any>;
/**
* 调用小程序cloud上的api
* @param data
*/
declare function invokeCloud({ type, data }: {
type: string;
data?: any;
}): Promise<any>;
/**
* 小程序的请求
* @param options
*/
declare function httpRequest<T = any>(options: {
path: string;
body?: any;
params?: Record<string, any>;
headers?: any;
method?: string;
exts?: Record<string, any>;
}): Promise<T>;
/**
* 只能在 web-view 端调用, 同一类消息可以注册多个事件回调
* @param type
* @param callback
*/
declare function listen(type: string, callback: (data?: any) => void): void;
/**
* 只能在 web-view 端调用,用于移除对应的事件监听
* @param type
*/
declare function removeListen(type: string): void;
export { invoke, listen, removeListen, invokeMy, invokeCloud, httpRequest };