Global Axios default values and custom instance defaults

Source: Internet
Author: User

First of all, let me tell you something.

After login successfully return token and then take token to continue the following request,

The strange thing is that the current page works, and the token disappears after the refresh and jump.

I checked the Axios document and found myself in the hole.

I set the global default token, but I'm going to customize the instance below but I don't have token set,

So here's the situation, and here's the code I changed.

The custom Axios response Interceptor instance is an Axios instance//HTTP request Interceptor Instance.interceptors.request.use (    config + =        cons Ole.dir (Localstorage.getitem (' token '))        if (Localstorage.getitem (' token ')! = null) {//Determine if token exists, if present, Each HTTP header is prefixed with token            config.headers.Authorization = Localstorage.getitem (' token ');        }        return config;    },    err = {        return promise.reject (ERR);    });

  

Global Axios default values and custom instance defaults

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.