当前位置:网站首页>Gestion centralisée des API
Gestion centralisée des API
2022-04-22 06:43:00 【Zhou zhuchi】
Un programme ne peut pas se passer d'une interface,Et comment gérer centralement l'interface du programme
Le programme peut - il effectuer une maintenance secondaire、Mise à jour,L'interface n'est pas assez flexible pour prendre une grande partie
L'interface d'un programme est brouillée,Je suis sûr que vous ne voudrez pas revoir une telle procédure(J'ai mal à la tête.)
Première étape encapsulation de la demande(request.js)
import Interceptor from "./core/interceptor";
import Request from "./index";
import indexConfig from "@/config/index.config"
export const globalInterceptor = {
request: new Interceptor(),
response: new Interceptor()
};
export const config = {
baseURL: indexConfig.baseUrl,
header: {
'token': uni.getStorageSync('Token_YunLiJian_Mp'),
contentType: "application/x-www-form-urlencoded"
// 'Content-Type': 'application/json'
}
};
globalInterceptor.request.use(
config => {
config.header = {
'token': uni.getStorageSync('Token_YunLiJian_Mp')
}
return config;
},
err => {
console.error(" Interception avant l'échec de la demande ", err);
return false;
}
);
globalInterceptor.response.use(
(res, config) => {
if (res.data.code == 1001 || res.data.code == 1002 || res.data.code == 1003) {
uni.setStorageSync('Token_YunLiJian_Mp', '') // En cas d'erreur de données ,Effacertoken
uni.setStorageSync('UserInFo_YunLiJian_Mp', '') // Effacer les données de l'utilisateur
uni.showModal({
title: 'Conseils du système',
content: 'Connexion expirée,Veuillez vous connecter à nouveau',
success: function(res) {
if (res.confirm) {
uni.switchTab({
url: `/pages/Home/Home`
})
} else if (res.cancel) {
uni.switchTab({
url: `/pages/Mimne/Mimne`
})
}
}
});
return null
}
return res;
},
(err, config) => {
console.error(" Échec de l'interception après la demande ");
console.error("Conseils d'erreur: ", err);
console.error("Message d'erreur: ", config);
return Promise.reject(err);
}
);
Étape 2 Gestion centralisée de l'interface

user.js

Étape 3 Utilisation de l'importation
- Importer

- Utiliser

De cette façon, si vous avez besoin d'entretien plus tard ,Ou mise à jour, Pour voir directement apiDocumentation,Simple et clair, Vous serez bientôt au courant du programme api Et la structure de base
版权声明
本文为[Zhou zhuchi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220557472553.html
边栏推荐
猜你喜欢

Wechat applet login process

MySQL is a classic question often asked in an interview.

The minors protection solution of digital beauty technology is heavily launched, opening a new era of minors' network escort

Multiple styles of scroll bars

COM in Wine(1)——COM基本概念

创新实训(四)前期准备—服务器

windows远程连接redis

TCP和UDP区别详解

MySQL备忘录(供自己查询所用)

Use PG_ STAT_ Replication monitoring replication
随机推荐
知网下载pdf(再也不想用CAJViewer啦!!!)
Uniapp wechat applet user authorization to obtain current location information Tencent map
Pgbackrest practice
The installation of redis is started and used by rookies (Windows)
LeetCode 1547:切棍子的最小成本
点击触发其他dom元素:< $refs,$el >
Using ltree to process hierarchical data in PostgreSQL
EXCEL 利用替换、分列、填充功能综合整理财务数据
uniapp web-view示例(微信小程序)
OLAP和OLTP的区别及所对应模型(基础知识)
Waterfall layout JS positioning
JS encodes and decodes the URL (the difference between the three methods)
pixel手机救砖教程
To summarize the timers I've used: @ scheduled annotation
ArcMAP TIN与栅格DEM的坡度坡向对比分析
关于调试指纹时候遇到的其他问题
JS judge the PC end or mobile end
创新实训(十)
ArcGIS 基于TIN地表面数据和建筑数据进行视域分析
Pure JS chain animation and simultaneous motion