增加数据缓存,去除部分请求的重复/
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token变量
|
||||
import {APIHOST} from './config.js'
|
||||
import {cacheClearAll} from '@/store/cashe.js'
|
||||
const install = (Vue, vm) => {
|
||||
// 此为自定义配置参数,具体参数见上方说明
|
||||
Vue.prototype.$u.http.setConfig({
|
||||
@@ -26,8 +27,8 @@ const install = (Vue, vm) => {
|
||||
// 所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
|
||||
const token = uni.getStorageSync('token');
|
||||
config.header.token = token;
|
||||
config.url=config.url.slice(0,1)==='/'?config.url.slice(1,config.url.length):config.url
|
||||
// config.header.Token = 'xxxxxx';
|
||||
|
||||
// 可以对某个url进行特别处理,此url参数为this.$u.get(url)中的url值
|
||||
// if(config.url == '/user/login') config.header.noToken = true;
|
||||
// 最后需要将config进行return
|
||||
@@ -38,6 +39,7 @@ const install = (Vue, vm) => {
|
||||
|
||||
// 响应拦截,判断状态码是否通过
|
||||
Vue.prototype.$u.http.interceptor.response = (res) => {
|
||||
console.log(res);
|
||||
if (res.code == 0) {
|
||||
// res为服务端返回值,可能有code,result等字段
|
||||
// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
|
||||
@@ -75,6 +77,7 @@ const install = (Vue, vm) => {
|
||||
uni.removeStorageSync("isInvitation")
|
||||
uni.removeStorageSync("zhiFuBao")
|
||||
uni.removeStorageSync("zhiFuBaoName")
|
||||
cacheClearAll()
|
||||
// 此为uView的方法,详见路由相关文档
|
||||
vm.$u.route('/pages/login/login')
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user