Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

vue CORS

//in your vue.config.js
module.exports = {
  devServer: {
    proxy: {
      "/api": {
        target: "<API BASE URL>",
        changeOrigin: true,
        pathRewrite: {
          "^/api": "",
        },
      },
    },
  },
}

//in store actions account.js

let corsAnywhere = "https://corsanywhere.herokuapp.com"

let options = {
  url:
  process.env.NODE_ENV === "production"
  ? `${corsAnywhere}/API BASE URL/END POINT`
  : "/api/END POINT",
  method: "GET",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  data: {},
}

axios(options).then(respnse => {}).catch(error => {})
 
PREVIOUS NEXT
Tagged: #vue #CORS
ADD COMMENT
Topic
Name
8+7 =