Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Losing cusomize property value when I add some customize property of AxiosRequestConfig #2500

Closed
zl7261 opened this issue Oct 28, 2019 · 3 comments

Comments

@zl7261
Copy link

zl7261 commented Oct 28, 2019

Axios version is ^0.19.0

I wanna add some customize filed in RequestConfig to control the HTTP request of Axios show loading gif or not.

But I found those customize filed is not found in the interceptor of Axios.

Here is my code.

interface RequestConfig extends AxiosRequestConfig {
    hideLoading?: boolean
    loadingText?: string
    warnType?: string
    hideWarn?: boolean
}


const service = axios.create({ 
})

export default {
get: (url: string, data: object, config: RequestConfig) => {
        let realConfig = {params: config, ...DEFAULT_CONFIG, config_flag: config};
        return service.get(url, realConfig)
    },
}

service.interceptors.request.use((request: RequestConfig) => {
    let url = request.url;
    if (!url) throw new Error('url is empty')
    if (!url.startsWith('/')) url = '/' + url;
    console.time(request.baseURL + url)
    if (!request.params.hideLoading) {  
// I can  only get propert's value which defined in AxiosRequestConfig, 
// not in my customized ReuqestConfig
        startLoading(request);
    }
    return request
}, (err: any) => {
    return Promise.reject(err);
});

In the interceptor's scope, the request doesn't contain any filed of RequestConfig.
But when I put my customized config in the filed of AxiosRequestConfig such as 'params'
It does works.

Does Axios ban the operate of customizing AxiosRequestConfig, such as add property, only return the pure properties of AxiosRequestConfig?

@zl7261 zl7261 changed the title Losing value when I customize AxiosRequestConfig Losing cusomize property value when I add some customize property of AxiosRequestConfig Oct 28, 2019
@yasuf
Copy link
Collaborator

yasuf commented Oct 28, 2019

I'll take a look at this whenever I get a chance, we have #2438 and #2490 as well

@yasuf
Copy link
Collaborator

yasuf commented Oct 29, 2019

See #2502 once that goes live this should work

@zl7261
Copy link
Author

zl7261 commented Oct 29, 2019

ty, waiting for release.
Already revert to 18.1 to fix it.

@zl7261 zl7261 closed this as completed Oct 29, 2019
@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants