fary-vue-http
v1.0.2
Published
A http plugin for vue, using axios.
Downloads
2
Readme
fary-vue-http
Usage
import Vue from 'vue'
import vueHttp, {
addRequestInterceptor,
addResponseInterceptor,
http,
} from 'fary-client-log'
Vue.use(vueHttp)
// add axios request interceptor
addRequestInterceptor(
(config) => {
config.url = `/api${config.url}`
return config
},
error => Promise.reject(error),
)
// add axios response interceptor
addResponseInterceptor(
response => response.data,
error => Promise.reject(error),
)
http.get('/somePath'/*, axios options */)
http.post('/somePath'/*, data, axios options */)
http.put('/somePath'/*, data, axios options */)
http.delete('/somePath'/*, axios options */)
// in any vue component instance:
this.http.get('/somePath'/*, axios options */)
this.http.post('/somePath'/*, data, axios options */)
this.http.put('/somePath'/*, data, axios options */)
this.http.delete('/somePath'/*, axios options */)
default headers
'Accept': 'application/json, text/plain, */*; charset=utf-8',
'Cache-Control': 'no-cache',
'Content-Type': 'application/json; charset=utf-8',
'Pragma': 'no-cache',
Dynamic proxy config interception for proxy target debugging.
This feature should Cooperate with fary
, see https://github.com/xkeshi/fary#dynamic-proxy-config-interception-for-proxy-target-debugging.
This plugin will read the localStorage, the key is proxyconfig
.