Answer the question
In order to leave comments, you need to log in
Why does nuxt axios have an OPTIONS method for all requests?
I connect nuxt axios to the nuxt config:
modules: [ '@nuxtjs/axios']
I do not change other parameters. When sending such a request in the component method:
this.$axios.$get(' some-host.com ') - in the console, the request has the OPTIONS method. In any get or post request, for some reason OPTIONS is substituted. If you specify the relative path this.$axios.$post('/some-url') , then the parameter with baseUrl localhost:3000 is substituted and sent by the desired method:
POST http://localhost:3000/some-url
But if you change the baseURL value to the desired host through the plugin, then again the request is made using the OPTIONS method
I managed to find out that this is related to CORS , and this problem can be solved through nuxt proxy , but I did not find a good example.
But if I directly use axios, then everything works correctly:
import axios from 'axios'
axios.get('http://some-url')
Answer the question
In order to leave comments, you need to log in
CORS , there is an image on the page. This makes the browser completely independent, neither nuxt nor axios has anything to do with it.
But if I directly use axios, then everything works correctly:
import axios from 'axios' axios.get('http://some-url')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question