Vue project agent configuration
Create the vue.config.js file in the root directory and add the following content
// Absolute path configuration const path = require('path'); Function resolve(dir){return path.join(__dirname,dir)//path.join(__dirname) set absolute path} module.exports = {// proxy DevServer: {open: true, proxy: {'/API: {target: 'http://192.168.1.235:8787', changeOrigin: true, pathRewrite: { '^/api': '}}}}, // Configure the absolute path chainWebpack:(config)=>{config.resolve.alias //set the first argument: set the alias, the second argument: Set the path. Set (' @ ', resolve ('. / SRC)). The set (' @ components, resolve () '. / SRC/components')}}Copy the code
Vue project Request encapsulation
SRC create the utils folder /request.js file and add the following contents
import axios from 'axios'//npm install axios --save import NProgress from 'nprogress'//npm install --save nprogress import 'nprogress/nprogress.css' const request = axios.create({ timeout: In 20000, }) / / request interceptor request. The interceptors. Request. Use (config = > {/ / store. Getters. Token && config. The headers = [' token '] GetToken () / / token NProgress. Start () return the config}) / / response interceptor request. The interceptors. Response. Use (response = > { NProgress.done() return Promise.resolve(response.data) }, error => { NProgress.done() return new Promise(() => { }) }) export default requestCopy the code