The interface response time is long, and the front-end returns a request timeout to solve

Set axios response time in front-end code

1. Globally set axios.defaults.timeout = time // the unit is milliseconds

or

2. Encapsulated http request

const service = axios.create({
    // 公共接口--这里注意后面会讲
    // baseURL: process.env.BASE_API,
    // eslint-disable-next-line no-undef
    baseURL: '/api',

    // 超时时间 单位是ms,这里设置了3s的超时时间
    timeout: 3 * 1000
})

or

3.

axios.post(url, params, { timeout: timeout })

It still times out after publishing online, and the NGINX configuration needs to be modified

The default response time of nginx is 60S

You also need to modify the nginx.conf file

Add under configured request proxy

in seconds

location /api {
    ...
    proxy_read_timeout 150;  # 秒
    ...
}

Guess you like

Origin blog.csdn.net/KK_vicent/article/details/129439676