Home > Software design >  Axios VueJS and open API
Axios VueJS and open API

Time:02-02

I am tryng to get data from a API. But when I use Insomnia ou direct on browser, it is ok.

When I use axios in my code, I have this error : Blocking of a multi-origin request (Cross-Origin Request): the "Same Origin" policy does not allow to consult the remote resource....

My code

const axiosInstance = axios.create({
    baseURL : 'https://trefle.io/api/v1/plants?token=********',
    mode: 'no-cors',
    withCredentials: false,
    credentials: 'same-origin',
    headers : {
        'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json',
    }
})


async getPlantsList(context)
        {
            try{            
                const response = await axiosInstance.get();

                console.log('2', response.data);

            } catch(error){
                console.log('error', error);
            }
        }

I need help, I search on web, but I do not find a solution.

Thank for your help

Add headers in axios instance

CodePudding user response:

Several issues:

  1. The enter image description here

  • Related