Work with Server | vue-element | vue element admin api
Front-endrequestflowInvue-element-admin,acompletefront-endUIinteractstotheserver-sideprocessingflowasfollows:UIcomponentinteraction;CallunifiedmanagementAPIservicerequestfunction;Sendrequestsusingencapsulatedrequest.js;Getserverreturn;Updatedata;Asyoucanseefromtheaboveflow,inordertofacilitatemanagementandmaintenance,unifiedrequestprocessingisplacedinthesrc/apifolderandthefilesaregenerallysplitaccordingtothemodellatitude,suchas:request.js@/utils/request.jsisbasedontheaxios[1],tofacilitatetheu...
Front-end request flowIn vue-element-admin , a complete front-end UI interacts to the server-side processing flow as follows:
UI component interaction; Call unified management API service request function; Send requests using encapsulated request.js; Get server return; Update data;As you can see from the above flow, in order to facilitate management and maintenance, unified request processing is placed in the src/api folder and the files are generally split according to the model latitude,such as:
request.js@/utils/request.js is based on the axios[1], to facilitate the uniform handling of POST, GET and other request parameters, request headers, and error messages。Specific can see request.js[2].
It encapsulates the global request interceptor, response interceptor,unified error handling, unified timeout, baseURL settings, etc.
An example of a request article list: Set multiple baseURLsWe can request multiple api addresses by setting multiple baseURL...