情不知从何起,一往而情深
排名
6
文章
199
粉丝
4
评论
3
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

ERROR Invalid options in vue.config.js: "proxy" is not allowed

5896人阅读 2023/3/23 11:55 总访问:1110297 评论:0 收藏:0 手机
分类: 前端

proxy应该配置到devServer下边不然就会出现标题描述的错误,如这种配置

  1. module.exports = {
  2. publicPath: "./",
  3. chainWebpack: (config) => {
  4. config.resolve.alias.set("_c", resolve("src/components")); // key,value自行定义,比如.set('@@', resolve('src/components'))
  5. },
  6. proxy: {
  7. "/api": {
  8. target: "http://localhost:7324", // 需要代理的后端接口
  9. changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求
  10. pathRewrite: {
  11. //重写匹配的字段,如果不需要在请求路径上,重写为""
  12. "^/api": "",
  13. },
  14. },
  15. },
  16. };

正确的配置应该是配置到devServer下方,如

  1. module.exports = {
  2. publicPath: "./",
  3. chainWebpack: (config) => {
  4. config.resolve.alias.set("_c", resolve("src/components")); // key,value自行定义,比如.set('@@', resolve('src/components'))
  5. },
  6. devServer: {
  7. proxy: {
  8. "/api": {
  9. target: "http://localhost:7324", // 需要代理的后端接口
  10. changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求
  11. pathRewrite: {
  12. //重写匹配的字段,如果不需要在请求路径上,重写为""
  13. "^/api": "",
  14. },
  15. },
  16. },
  17. },
  18. };

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价