1.1.1 • Published 6 years ago
vue-plugin-other v1.1.1
vue-plugin-other
目前只含网络请求功能($http)
Installing
Using npm:
$ npm install axios
Example
在脚手架的入口文件main.js
import Vue from 'vue'
import {pAjax} from 'vue-plugin-other';
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-other';
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-other';
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]