CORS issue with Vue.js

后端 未结 5 737
鱼传尺愫
鱼传尺愫 2020-12-03 03:37

I\'m using:

  • Vue 2.0.3
  • vue-router 2.0.1
  • vuex 0.8.2
  • vue-resource 0.7.0

And after trying to login to my page when using

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 04:19

    You face this error when the API url and client url aren't the same. Vue CLI 3 (and in the core of it, Webpack) allows you to proxy your API url to your client url.

    Inside vue.config.js file add following lines:

    // vue.config.js
    module.exports = {
      // options...
      devServer: {
            proxy: 'https://mywebsite/',
        }
    }
    

    And then send your ajax calls to http://localhost/api/.

    You can read the full article here: How to deal with CORS error on Vue CLI 3?

提交回复
热议问题