PropertyApp/node_modules/vue-jsonp/dist/index.d.ts
2025-03-18 17:52:16 +08:00

102 lines
2.4 KiB
TypeScript

/**
* Vue Jsonp.
* # Carry Your World #
*
* @author: LancerComet
* @license: MIT
*/
import { PluginObject } from 'vue/types/plugin';
declare module 'vue/types/vue' {
interface Vue {
$jsonp: typeof jsonp;
}
}
/**
* JSONP Vue plugin.
*
* @example
* Vue.use(VueJsonp)
*/
declare const VueJsonp: PluginObject<never>;
/**
* Make a json request.
*
* @template T
* @param {string} url Target URL address.
* @param {IJsonpParam} [param={}] Querying params object.
* @param {number} [timeout] Timeout setting (ms).
* @returns {Promise<T>}
*
* @example
* const data = await jsonp<string>('/url', {
* type: 'admin',
* date: '2020'
* })
*/
declare function jsonp<T = any>(url: string, param?: IJsonpParam, timeout?: number): Promise<T>;
declare function jsonp<T = any>(url: string, param?: IJsonpParam, config?: IConfig): Promise<T>;
export { VueJsonp, jsonp };
/**
* JSONP parameter declaration.
*/
interface IJsonpParam {
/**
* Callback query name.
* This param is used to define the query name of the callback function.
*
* @example
* // The request url will be "/some-url?myCallback=jsonp_func&myCustomUrlParam=veryNice"
* const result = await jsonp('/some-url', {
* callbackQuery: 'myCallback',
* callbackName: 'jsonp_func',
* myCustomUrlParam: 'veryNice'
* })
*
* @default callback
*/
callbackQuery?: string;
/**
* Callback function name.
* This param is used to define the jsonp function name.
*
* @example
* // The request url will be "/some-url?myCallback=jsonp_func&myCustomUrlParam=veryNice"
* const result = await jsonp('/some-url', {
* callbackQuery: 'myCallback',
* callbackName: 'jsonp_func',
* myCustomUrlParam: 'veryNice'
* })
*
* @default jsonp_ + randomStr()
*/
callbackName?: string;
/**
* Custom data.
*/
[key: string]: any;
}
/**
* JSONP Config.
*/
interface IConfig {
/**
* Request timeout, ms.
*
* @default 5000
*/
timeout?: number;
/**
* This is the indicator that used in query string to indicate arrays.
*
* @example
* // When you pass a '[]' or nothing:
* a[]=1&a[]=2&a[]=3 // This form is used widely.
*
* // An empty sring was passed:
* a=1&a=2&a=3 // This is a custom example.
*
* @default '[]'
*/
arrayIndicator?: string;
}