定义一些常量字符,类似其他语言的枚举。如果你是用的是Typescript,还可以用来做类型判断等。
httpEnum
注意ResultEnum需要和后端的code保持一致
创建src/enums/httpEnum.js
,写入以下内容:
enums/httpEnum.js
export const ResultEnum = { SUCCESS: 2000, ERROR: -1, TIMEOUT: 10042, TOKEN_TIMEOUT: 10041, TYPE: 'success', };
export const RequestEnum = { GET: 'GET', POST: 'POST', PATCH: 'PATCH', PUT: 'PUT', DELETE: 'DELETE', };
export const ContentTypeEnum = { JSON: 'application/json;charset=UTF-8', TEXT: 'text/plain;charset=UTF-8', FORM_URLENCODED: 'application/x-www-form-urlencoded;charset=UTF-8', FORM_DATA: 'multipart/form-data;charset=UTF-8', };
|
pageEnum
创建src/enums/pageEnum.js
,写入以下内容:
enums/pageEnum.jsexport const PageEnum = { BASE_LOGIN: '/login', BASE_LOGIN_NAME: 'Login', REDIRECT: '/redirect', REDIRECT_NAME: 'Redirect', BASE_HOME: '/dashboard', BASE_HOME_REDIRECT: '/dashboard/console', ERROR_PAGE_NAME: 'ErrorPage', };
|