增加数据缓存,去除部分请求的重复/

This commit is contained in:
2024-12-30 16:31:01 +08:00
parent cbcd1c857c
commit 6fb98974d6
15 changed files with 697 additions and 320 deletions

View File

@@ -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为服务端返回值可能有coderesult等字段
// 这里对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;