1.1.3 • Published 6 years ago

vue-plugin-http v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

vue-plugin-http

网络请求功能($http)

Installing

Using npm:

$ npm install vue-plugin-http

Example

在脚手架的入口文件main.js

import Vue from 'vue'
import {pAjax} from 'vue-plugin-http';
Vue.use(pAjax);

常用请求 ---支持 get 请求

this.$http.get(url,params).then(res=>{
    console.log(res)
}).catch(err=>{
    console.log(err)
})

支持 post 请求

this.$http.get(url,params).then(res=>{
    console.log(res)
}).catch(err=>{
    console.log(err)
})

更多请求需要配置 在main.js文件

import Vue from 'vue'
import {pAjax} from 'vue-plugin-http';
Vue.use(pAjax);

//建议将以下文件抽离成单文件
Vue.prototype.$http.config={
    baseUrl:'',
    timeout:'',
    headers:''
}
//或者 只配置单项
//Vue.prototype.$http.config.baseUrl='http://xxx'

拦截器配置

import Vue from 'vue'
import {pAjax} from 'vue-plugin-http';
Vue.use(pAjax);

//建议将以下文件抽离成单文件

//请求拦截器
const fn1=function(request){
    //做点什么
    return request
}
const error1=function(err){
    //错误处理

    return Promise.reject(err);
}
Vue.prototype.$http.interceptors.request=[fn1,error1] 


//响应拦截器
const fn2=function(request){
    //做点什么
    return request
}
const error2=function(err){
    //错误处理

    return Promise.reject(err);
}
Vue.prototype.$http.interceptors.response=[fn2,error2] 
1.1.3

6 years ago

1.1.2

6 years ago