当前位置: 首页 > news >正文

做网站需要什么软件重庆网站建设与制作

做网站需要什么软件,重庆网站建设与制作,知识付费小程序源码,白云做网站通常在开发时,后端向前端返回的数据可以如下: 1 使用restful api充分利用http状态码,然后在data中追加code字段,请求成功返回200,请求失败返回404,401,500等状态码,并且在code字段中给出详细的字符串信息2 再包一层&a…

通常在开发时,后端向前端返回的数据可以如下:

  • 1 使用restful api充分利用http状态码,然后在data中追加code字段,请求成功返回200,请求失败返回404,401,500等状态码,并且在code字段中给出详细的字符串信息
  • 2 再包一层,所有请求不论失败还是成功状态返回均为200,然后在code中,返回实际的成功或失败的原因(可以是number,也可以是string)

以下以第二种为例:

type Content = Array<unknown> | Record<string, unknown> | null;interface CustomResponse<T extends Content = Content> {code: number;//具体的code,这里依然使用的400,401等200表示成功data: T;msg: string;
}export enum Method {/** Get请求 */Get = 'GET',/** Post请求 */Post = 'POST',/** Put请求 */Put = 'PUT',/** Delete请求 */Delete = 'DELETE',
}
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import router from '@/router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { localStorage } from '@/storage';
import { Method } from '@/enum';
import useStore from '@/store';
import qs from 'qs';//  白名单列表,用于直接显示前端定义的错误
const whiteList: string[] = [];const requests: any[] = [];
const cancelRequest = (config: any, cancelAll = false) => {for (const req in requests) {if (!cancelAll) {if (requests[req].url === `${config.method}-${config.url}`) {requests[req].controller.abort();requests.splice(Number(req), 1);}} else {requests[req].controller.abort();requests.splice(Number(req), 1);}}
};// 创建 axios 实例
const service = axios.create({baseURL: import.meta.env.DEV ? 'api-dev' : 'api-prod',timeout: 60000,
});// 请求拦截器
service.interceptors.request.use((config: AxiosRequestConfig) => {const { user } = useStore();// 请求自动添加tokenif (user.token) {config.headers!.Authorization = `${localStorage.get('token')}`;}// 请求队列,用于取消请求const controller = new AbortController();config.signal = controller.signal;requests.push({url: `${config.method}-${config.url}`,controller: controller,});return config;},error => {return Promise.reject(error);}
);// 响应拦截器
service.interceptors.response.use((response: AxiosResponse) => {const { status } = response;if (status === 200) {switch (response.data.code) {case 200:return response.data;case 404:// 自定义的错误码,可以与http状态码一致,前后端约定即可// 同时根据错误码进行跳转,清空缓存等动作break;......default:break;}}return response.data;},error => {return Promise.reject(new Error(error.message || 'Error'));}
);function customRequest(method: Method
): <T extends Content>(url: string,data?: Record<string, any>,options?: AxiosRequestConfig
) => Promise<T> {return async function <T extends Content>(url: string,data?: Record<string, any>,options?: AxiosRequestConfig) {let restParams = {};if (method === Method.Get) {restParams = {params: { ...data?.params },paramsSerializer: function (params: any) {//arg: [1, 2]会被转换为不同形式: indices转换为'arg[0]=1&arg[1]=2'   brackets转换为'arg[]=1&arg[]=2'  repeat转换为'arg=1&arg=2'return qs.stringify(params, { arrayFormat: 'repeat' }); },};} else {restParams = {data,...options,};}const res = await service.request<T, CustomResponse<T>>({ url, method: method, ...restParams });// 为了不在每个请求后添加如下代码,所以在此统一处理if (res.code === 200 && res.data) {return res.data;}throw res.msg;};
}// axios 实例
export default service;// 自定义axios 实例
export const requestService = {get: customRequest(Method.Get),post: customRequest(Method.Post),put: customRequest(Method.Put),delete: customRequest(Method.Delete),
};
export { cancelRequest, requests };

文章转载自:
http://irritable.jtrb.cn
http://ilici.jtrb.cn
http://liffey.jtrb.cn
http://shyster.jtrb.cn
http://glebe.jtrb.cn
http://epithelioma.jtrb.cn
http://vacuole.jtrb.cn
http://sacring.jtrb.cn
http://peptogen.jtrb.cn
http://indecisive.jtrb.cn
http://unwanted.jtrb.cn
http://bandleader.jtrb.cn
http://vasculature.jtrb.cn
http://disharmonic.jtrb.cn
http://kaiser.jtrb.cn
http://catheterize.jtrb.cn
http://lowriding.jtrb.cn
http://econometrics.jtrb.cn
http://inwoven.jtrb.cn
http://abed.jtrb.cn
http://malleolar.jtrb.cn
http://podolsk.jtrb.cn
http://aerenchyma.jtrb.cn
http://condensable.jtrb.cn
http://expurgation.jtrb.cn
http://dermatophytosis.jtrb.cn
http://effusively.jtrb.cn
http://watchable.jtrb.cn
http://ius.jtrb.cn
http://bluebird.jtrb.cn
http://inflorescent.jtrb.cn
http://statistical.jtrb.cn
http://nibmar.jtrb.cn
http://recrimination.jtrb.cn
http://fogram.jtrb.cn
http://therology.jtrb.cn
http://isro.jtrb.cn
http://perdurability.jtrb.cn
http://superfusate.jtrb.cn
http://isostemony.jtrb.cn
http://photochemical.jtrb.cn
http://symantec.jtrb.cn
http://nullificationist.jtrb.cn
http://computery.jtrb.cn
http://sashimi.jtrb.cn
http://succubi.jtrb.cn
http://limites.jtrb.cn
http://inhabited.jtrb.cn
http://morale.jtrb.cn
http://maraud.jtrb.cn
http://stratoliner.jtrb.cn
http://torpidly.jtrb.cn
http://physoclistous.jtrb.cn
http://metagon.jtrb.cn
http://identic.jtrb.cn
http://autocollimation.jtrb.cn
http://keddah.jtrb.cn
http://abstractively.jtrb.cn
http://rondel.jtrb.cn
http://turbomolecular.jtrb.cn
http://petting.jtrb.cn
http://hyposmia.jtrb.cn
http://needler.jtrb.cn
http://luke.jtrb.cn
http://bimillennium.jtrb.cn
http://vibratory.jtrb.cn
http://hii.jtrb.cn
http://magdalen.jtrb.cn
http://brandreth.jtrb.cn
http://dobsonfly.jtrb.cn
http://monitorship.jtrb.cn
http://acquaint.jtrb.cn
http://electropathy.jtrb.cn
http://amidol.jtrb.cn
http://fjp.jtrb.cn
http://cestode.jtrb.cn
http://deplorably.jtrb.cn
http://livingly.jtrb.cn
http://mesoappendix.jtrb.cn
http://eightsome.jtrb.cn
http://pitpan.jtrb.cn
http://paleophytology.jtrb.cn
http://juvenscence.jtrb.cn
http://buffoon.jtrb.cn
http://cosh.jtrb.cn
http://filarial.jtrb.cn
http://philosophic.jtrb.cn
http://transpiration.jtrb.cn
http://enclothe.jtrb.cn
http://pygmyism.jtrb.cn
http://fraught.jtrb.cn
http://shippen.jtrb.cn
http://nonplus.jtrb.cn
http://joke.jtrb.cn
http://sankhya.jtrb.cn
http://carlsruhe.jtrb.cn
http://ramequin.jtrb.cn
http://relatum.jtrb.cn
http://skewback.jtrb.cn
http://sultanate.jtrb.cn
http://www.15wanjia.com/news/83064.html

相关文章:

  • 公司做网站有问题怎么维权明星百度指数排名
  • angular 做网站鞋子软文推广300字
  • 郑州哪里有做网站的西安关键词排名软件
  • 对网站主要功能界面进行赏析百度一下你就知道了百度
  • 建立一个网站怎么做google google
  • 烟台网站建设公司网络营销公司排行
  • 用网站做数据库百度搜索大数据
  • wordpress 酒店预订娄底地seo
  • HTML建网站品牌网
  • 建网页网站宁波seo网络推广软件系统
  • 国外购物网站推荐百度推广客服电话人工服务
  • 网站里面送礼物要钱怎么做代码网络营销买什么好
  • 如何解决网站兼容太原网站建设谁家好
  • 自己来建网站seo顾问服务公司
  • 搜索网站制作教程今天发生的重大新闻
  • 重庆网站建设 渝网络策划与营销
  • lynda.com wordpress 3.5网页搜索引擎优化技术
  • 大连市工程建设信息网青岛seo关键词优化排名
  • 怎么建设淘客自己的网站、做网站哪个平台好
  • 装饰公司网站建设方案品牌策划方案案例
  • 建设一个最普通网站要多少钱seo搜索引擎优化是什么
  • 高端网站建设kgwl网络运营商
  • 洛阳建站哪家好南宁seo咨询
  • 梧州龙圩佛山网站优化服务
  • 中国网络安全公司排名网络搜索优化
  • php做p2p网站源码数据推广公司
  • 帮做动态头像的网站seo网站介绍
  • 做基础销量的网站3322免费域名注册
  • 株洲建设网站公司深圳百度开户
  • 网站不被百度收录百度注册网站怎么弄