mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
add vue-resource
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/// <reference path="./vue-resource.d.ts" />
|
||||
|
||||
Vue.http.options.root = '/root';
|
||||
Vue.http.headers.common['Authorization'] = 'Basic YXBpOnBhc3N3b3Jk';
|
||||
|
||||
new Vue({
|
||||
http: {
|
||||
root: '/root',
|
||||
headers: {
|
||||
Authorization: 'Basic'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Vue.http.options.emulateJSON = true;
|
||||
Vue.http.options.emulateHTTP = true;
|
||||
|
||||
class App extends Vue {
|
||||
ready() {
|
||||
this.$http({ url: '/someUrl', method: 'GET' }).then((response) => {
|
||||
//
|
||||
}, (response) => {
|
||||
//
|
||||
});
|
||||
|
||||
this.$http.get('/someUrl').then((response) => {
|
||||
const status = response.status;
|
||||
const headers = response.headers();
|
||||
response.headers('expires');
|
||||
|
||||
this.$set('someData', response.data);
|
||||
});
|
||||
|
||||
var resource = this.$resource('someItem/{id}');
|
||||
resource.get({id: 1}).then((response) => {});
|
||||
resource.save({id: 1}, {item: 30}).then((responce) => {});
|
||||
}
|
||||
}
|
||||
|
||||
Vue.http.get('/someUrl', {}, {});
|
||||
|
||||
Vue.http.interceptors.push({
|
||||
request: function(request) {
|
||||
return request;
|
||||
},
|
||||
response: function(response) {
|
||||
return response;
|
||||
}
|
||||
});
|
||||
|
||||
Vue.http.interceptors.push(function() {
|
||||
return {
|
||||
request: function(request) {
|
||||
return request;
|
||||
},
|
||||
response: function(response) {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
});
|
||||
Vendored
+123
@@ -0,0 +1,123 @@
|
||||
// Type definitions for vue-resoure 0.7.0
|
||||
// Project: https://github.com/vuejs/vue-resource
|
||||
// Definitions by: kaorun343 <https://github.com/kaorun343>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../vue/vue.d.ts" />
|
||||
|
||||
declare namespace vuejs {
|
||||
|
||||
interface HttpHeaders {
|
||||
put?: { [key: string]: string };
|
||||
post?: { [key: string]: string };
|
||||
patch?: { [key: string]: string };
|
||||
delete?: { [key: string]: string };
|
||||
common?: { [key: string]: string };
|
||||
custom?: { [key: string]: string };
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface HttpResponse {
|
||||
data: Object;
|
||||
ok: boolean;
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: Function;
|
||||
}
|
||||
|
||||
interface HttpOptions {
|
||||
url?: string;
|
||||
method?: string;
|
||||
data?: any;
|
||||
params?: any;
|
||||
headers?: any;
|
||||
beforeSend?(request: any): any;
|
||||
emulateHTTP?: boolean;
|
||||
emulateJSON?: boolean;
|
||||
xhr?: any;
|
||||
upload?: any;
|
||||
jsonp?: string;
|
||||
timeout?: string;
|
||||
}
|
||||
|
||||
interface $http {
|
||||
(url: string, data?: any, options?: HttpOptions): PromiseLike<HttpResponse>;
|
||||
(url: string, options?: HttpOptions): PromiseLike<HttpResponse>;
|
||||
}
|
||||
|
||||
interface HttpInterceptor {
|
||||
request?(request: HttpOptions): HttpOptions;
|
||||
response?(response: HttpResponse): HttpResponse;
|
||||
}
|
||||
|
||||
interface Http {
|
||||
options: HttpOptions & { root: string };
|
||||
headers: HttpHeaders;
|
||||
interceptors: (HttpInterceptor | (() => HttpInterceptor))[];
|
||||
get: $http;
|
||||
post: $http;
|
||||
put: $http;
|
||||
patch: $http;
|
||||
delete: $http;
|
||||
jsonp: $http;
|
||||
}
|
||||
|
||||
interface ResourceActions {
|
||||
get: { method: string };
|
||||
save: { method: string };
|
||||
query: { method: string };
|
||||
update: { method: string };
|
||||
remove: { method: string };
|
||||
delete: { method: string };
|
||||
}
|
||||
|
||||
interface ResourceMethod {
|
||||
(params: any, data?: any, success?: Function, error?: Function): PromiseLike<HttpResponse>;
|
||||
(params: any, success?: Function, error?: Function): PromiseLike<HttpResponse>;
|
||||
(success?: Function, error?: Function): PromiseLike<HttpResponse>;
|
||||
}
|
||||
|
||||
interface ResourceMethods {
|
||||
get: ResourceMethod;
|
||||
save: ResourceMethod;
|
||||
query: ResourceMethod;
|
||||
update: ResourceMethod;
|
||||
remove: ResourceMethod;
|
||||
delete: ResourceMethod;
|
||||
}
|
||||
|
||||
interface $resource {
|
||||
(url: string, params?: Object, actions?: any, options?: HttpOptions): ResourceMethods;
|
||||
}
|
||||
|
||||
interface Resource extends $resource {
|
||||
actions: ResourceActions;
|
||||
}
|
||||
|
||||
interface Vue {
|
||||
$http: {
|
||||
(options: HttpOptions): PromiseLike<HttpResponse>;
|
||||
get: $http;
|
||||
post: $http;
|
||||
put: $http;
|
||||
patch: $http;
|
||||
delete: $http;
|
||||
jsonp: $http;
|
||||
};
|
||||
$resource: $resource;
|
||||
}
|
||||
|
||||
interface VueStatic {
|
||||
http: Http;
|
||||
resource: Resource;
|
||||
}
|
||||
|
||||
interface ComponentOption {
|
||||
http?: (HttpOptions & { headers?: HttpHeaders } & { [key: string]: any })
|
||||
}
|
||||
}
|
||||
|
||||
declare module "vue-resource" {
|
||||
const install: (vue: vuejs.VueStatic) => void;
|
||||
export = install;
|
||||
}
|
||||
Reference in New Issue
Block a user