{"id":3684,"date":"2024-11-10T09:32:52","date_gmt":"2024-11-10T01:32:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3684\/"},"modified":"2024-11-10T09:32:52","modified_gmt":"2024-11-10T01:32:52","slug":"vue-config-js-%e4%b8%ad%e9%85%8d%e7%bd%ae-proxy-%e8%a7%a3%e5%86%b3%e8%b7%a8%e5%9f%9f%e9%97%ae%e9%a2%98%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bb%8d%e7%84%b6%e5%ad%98%e5%9c%a8%e8%b7%a8%e5%9f%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3684\/","title":{"rendered":"Vue.config.js \u4e2d\u914d\u7f6e proxy \u89e3\u51b3\u8de8\u57df\u95ee\u9898\uff0c\u4e3a\u4ec0\u4e48\u4ecd\u7136\u5b58\u5728\u8de8\u57df\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173111868470777.jpg\" class=\"aligncenter\" title=\"Vue.config.js \u4e2d\u914d\u7f6e proxy \u89e3\u51b3\u8de8\u57df\u95ee\u9898\uff0c\u4e3a\u4ec0\u4e48\u4ecd\u7136\u5b58\u5728\u8de8\u57df\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"Vue.config.js \u4e2d\u914d\u7f6e proxy \u89e3\u51b3\u8de8\u57df\u95ee\u9898\uff0c\u4e3a\u4ec0\u4e48\u4ecd\u7136\u5b58\u5728\u8de8\u57df\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6b63\u786e\u914d\u7f6e .config.js \u4e2d\u7684 proxy \u6765\u89e3\u51b3\u8de8\u57df\u95ee\u9898<\/strong><\/p>\n<p>\u5728 vue.config.js \u4e2d\u914d\u7f6e proxy \u662f\u5904\u7406\u8de8\u57df\u95ee\u9898\u7684\u4e00\u79cd\u5e38\u89c1\u65b9\u6cd5\u3002\u4f46\u6709\u65f6\u5373\u4f7f\u914d\u7f6e\u6b63\u786e\uff0c\u8de8\u57df\u95ee\u9898\u4ecd\u7136\u5b58\u5728\u3002<\/p>\n<p><strong>\u5e38\u89c1\u9519\u8bef<\/strong><\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u914d\u7f6e\u793a\u4f8b\uff0c\u4f46\u53ef\u80fd\u5b58\u5728\u9519\u8bef\uff1a<\/p>\n<pre>if(config.resType) {\n    config.baseURL = \u2018\/hyjk_authorization\u2019; \/\/ \u5224\u65ad\u8bf7\u6c42\u5730\u5740\n  } else {\n    config.baseURL = process.env.VUE_APP_BASE_API;\n  }\n\nproxy: {\n      '\/hyjk_authorization': {\n        target: 'http:\/\/211.90.39.00:8089\/', \u8de8\u57df\u7684\u5730\u5740\n        changOrigin: true,\n        pathRewrite: {\n          '^\/hyjk_authorization':''\n        }\n      }\n    }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b63\u786e\u914d\u7f6e<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u770b\u4e0a\u53bb\u4ee3\u7801\u914d\u7f6e\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u68c0\u67e5\u4ee3\u7406\u5730\u5740\u662f\u5426\u6b63\u786e\u3002\u5c1d\u8bd5\u4ee3\u7406\u5230\u4e00\u4e2a\u5141\u8bb8\u8de8\u57df\u7684\u5730\u5740\uff0c\u4f8b\u5982: https:\/\/www.lilnong.top\/cors\/\u3002<\/li>\n<li>\u786e\u4fddpathRewrite\u89c4\u5219\u6b63\u786e\u3002\u6b64\u89c4\u5219\u5e94\u5c06\u8bf7\u6c42\u8def\u5f84\u91cd\u5199\u4e3a\u4ee3\u7406\u76ee\u6807\u3002\u786e\u4fdd&#8217;^\/hyjk_authorization&#8217;\u548c&#8221;\u4e4b\u95f4\u7684\u5339\u914d\u5668\u548c\u66ff\u6362\u7b26\u4e4b\u95f4\u6ca1\u6709\u7a7a\u683c\u3002<\/li>\n<li>\u91cd\u542f\u5e94\u7528\u7a0b\u5e8f\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u7f51\u7edc\u7545\u901a\uff0c\u5e76\u6392\u9664\u7f51\u7edc\u6545\u969c\u7684\u53ef\u80fd\u6027\u3002<\/li>\n<li>\u786e\u8ba4\u4ee3\u7406\u8bbe\u7f6e\u662f\u5426\u5df2\u5728\u670d\u52a1\u5668\u7aef\u6b63\u786e\u914d\u7f6e\u3002<\/li>\n<li>\u68c0\u67e5\u662f\u5426\u5b58\u5728\u5176\u4ed6\u53ef\u80fd\u5bfc\u81f4\u8de8\u57df\u95ee\u9898\u7684\u56e0\u7d20\uff0c\u4f8b\u5982 HTTP \u6807\u5934\u6216 CORS \u7b56\u7565\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fVue.config.js \u4e2d\u914d\u7f6e proxy \u89e3\u51b3\u8de8\u57df\u95ee\u9898\uff0c\u4ecd\u7136\u5b58\u5728\u8de8\u57df\u95ee\u9898\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6b63\u786e\u914d\u7f6e .config.js \u4e2d\u7684 proxy \u6765\u89e3\u51b3\u8de8\u57df\u95ee\u9898 \u5728 vue.config.js \u4e2d\u914d\u7f6e proxy \u662f\u5904\u7406\u8de8\u57df\u95ee\u9898\u7684\u4e00\u79cd\u5e38\u89c1\u65b9\u6cd5\u3002\u4f46\u6709\u65f6\u5373\u4f7f\u914d\u7f6e\u6b63\u786e\uff0c\u8de8\u57df\u95ee\u9898\u4ecd\u7136\u5b58\u5728\u3002 \u5e38\u89c1\u9519\u8bef \u4ee5\u4e0b\u4ee3\u7801\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u914d\u7f6e\u793a\u4f8b\uff0c\u4f46\u53ef\u80fd\u5b58\u5728\u9519\u8bef\uff1a if(config.resType) { config.baseURL = \u2018\/hyjk_authorization\u2019; \/\/ \u5224\u65ad\u8bf7\u6c42\u5730\u5740 } else { config.baseURL = process.env.VUE_APP_BASE_API; } proxy: { &#8216;\/hyjk_authorization&#8217;: { target: &#8216;http:\/\/211.90.39.00:8089\/&#8217;, \u8de8\u57df\u7684\u5730\u5740 changOrigin: true, pathRewrite: { &#8216;^\/hyjk_authorization&#8217;:&#8221; } } } \u767b\u5f55\u540e\u590d\u5236 \u6b63\u786e\u914d\u7f6e \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u770b\u4e0a\u53bb\u4ee3\u7801\u914d\u7f6e\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u9700\u8981\u6ce8\u610f\uff1a \u68c0\u67e5\u4ee3\u7406\u5730\u5740\u662f\u5426\u6b63\u786e\u3002\u5c1d\u8bd5\u4ee3\u7406\u5230\u4e00\u4e2a\u5141\u8bb8\u8de8\u57df\u7684\u5730\u5740\uff0c\u4f8b\u5982: https:\/\/www.lilnong.top\/cors\/\u3002 \u786e\u4fddpathRewrite\u89c4\u5219\u6b63\u786e\u3002\u6b64\u89c4\u5219\u5e94\u5c06\u8bf7\u6c42\u8def\u5f84\u91cd\u5199\u4e3a\u4ee3\u7406\u76ee\u6807\u3002\u786e\u4fdd&#8217;^\/hyjk_authorization&#8217;\u548c&#8221;\u4e4b\u95f4\u7684\u5339\u914d\u5668\u548c\u66ff\u6362\u7b26\u4e4b\u95f4\u6ca1\u6709\u7a7a\u683c\u3002 \u91cd\u542f\u5e94\u7528\u7a0b\u5e8f\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002 \u5176\u4ed6\u6ce8\u610f\u4e8b\u9879 \u786e\u4fdd\u7f51\u7edc\u7545\u901a\uff0c\u5e76\u6392\u9664\u7f51\u7edc\u6545\u969c\u7684\u53ef\u80fd\u6027\u3002 \u786e\u8ba4\u4ee3\u7406\u8bbe\u7f6e\u662f\u5426\u5df2\u5728\u670d\u52a1\u5668\u7aef\u6b63\u786e\u914d\u7f6e\u3002 \u68c0\u67e5\u662f\u5426\u5b58\u5728\u5176\u4ed6\u53ef\u80fd\u5bfc\u81f4\u8de8\u57df\u95ee\u9898\u7684\u56e0\u7d20\uff0c\u4f8b\u5982 HTTP \u6807\u5934\u6216 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3684","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3684"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3684\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}