After axios configures token information in header, a request from the backend will report a cross-domain problem. But there's nothing wrong with testing with postman.

as shown in the figure

clipboard.png

clipboard.png

//axios 
import axios from "axios"
axios.defaults.withCredentials = true;  //
const service=axios.create({
    baseURL:`${base}${itempath}`,
    timeout:5000
})
service.interceptors.request.use(
    config=>{
        if(store.getters.token){
            config.headers={
                "token":getToken(),
                "Accept":"application/json",
                "Content-Type":"application/json;charset=UTF-8"
            }
        }
        return config;
    },
    error=>{
        console.log(error);
        Promise.reject(error);
    }
)

the backend is also cross-domain, which can be requested normally before.

Mar.31,2022

token is a non-standard header, which requires the backend to output Access-Control-Allow-Origin headers in header. In addition, there is no cross-domain problem in the request in postman. Only


can you post a screenshot of the backend code

Menu