vue-cli3设置代理无效

vue-cli3设置代理无效
这是我设置代理的代码:
module.exports = {
devServer: {

open: true,
proxy: {
  '/news': {
    target: 'http://192.168.1.244/api',
    ws: true,
    changeOrigin: true
  }
}

}
}
报错:
Failed to load http://192.168.1.244/api/news...: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access

阅读 12.2k
3 个回答

写法不对。

open: true,
proxy: {
  '/api': {
    target: 'http://192.168.1.244',
    ws: true,
    changeOrigin: true
  }
}
请求时候直接写 axios.get('/api/news')

项目根目录下创建 vue.config.js 内容如下

module.exports = {
  devServer: {
    proxy: "http://192.168.1.244",
    https: false
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏