{"id":1308,"date":"2023-03-18T11:15:39","date_gmt":"2023-03-18T03:15:39","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1308"},"modified":"2023-04-29T09:14:18","modified_gmt":"2023-04-29T01:14:18","slug":"vue-js-http-request-proxy-configuration","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/vue-js-http-request-proxy-configuration\/","title":{"rendered":"Vue.js HTTP\u8bf7\u6c42\u4ee3\u7406\u914d\u7f6e"},"content":{"rendered":"<p>Vue.js\u4f7f\u7528axios\u5411\u670d\u52a1\u5668\u8bf7\u6c42\u6570\u636e\u65f6\uff0c\u7ecf\u5e38\u62a5\u8de8\u57df\u9519\u8bef<\/p>\n<pre><code>&#039;Access-Control-Allow-Origin&#039; header is present on the requested resource<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a\u914d\u7f6e\u4ee3\u7406<\/p>\n<p>\u5728<code>config\/index.js<\/code>\u4e2d<code>proxyTable<\/code>\u6dfb\u52a0<\/p>\n<pre><code class=\"language-javascript\">proxyTable: {\n  &#039;\/api&#039;: {                               \/\/ \u8981\u4ee3\u7406\u7684\u63a5\u53e3\u540d\n    target: &#039;http:\/\/192.168.1.1:8080\/&#039;,   \/\/ \u8981\u4ee3\u7406\u7684\u63a5\u53e3\u5730\u5740\n    changeOrigin: true,                   \/\/ \u5141\u8bb8\u8de8\u57df\n    pathRewrite: { &#039;^\/api&#039;: &#039;&#039; }          \/\/ \u63a5\u53e3\u540d\u91cd\u5199\n  },<\/code><\/pre>\n<p>\u7136\u540e\u5728<code>main.js<\/code>\u4e2d\u58f0\u660e\u4e00\u4e2a\u5168\u5c40<\/p>\n<pre><code class=\"language-javascript\">Vue.prototype.HOST = &#039;\/api&#039;<\/code><\/pre>\n<p>\u5373\u53ef\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528<\/p>\n<pre><code class=\"language-javascript\">var url = this.HOST + &quot;\/user?&quot;;\n    this.$axios.get(url, {\n    params: {\n        name: this.name,  \/\/\u4e0a\u4f20\u53c2\u6570\u5230\u670d\u52a1\u5668\n        id: this.id\n    }\n    }).then(res =&gt; {\n        var a =res.data.code;\n        console.log(a);  \/\/\u4ece\u670d\u52a1\u5668\u53d6\u5f97\u6570\u636eres\uff0c\u8fd9\u91cc\u6211\u4eec\u9700\u8981data\u91cc\u9762\u7684code\n      })\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Vue.js\u4f7f\u7528axios\u5411\u670d\u52a1\u5668\u8bf7\u6c42\u6570\u636e\u65f6\uff0c\u7ecf\u5e38\u62a5\u8de8\u57df\u9519\u8bef &#039;Access-Control-All [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1308","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1308"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1308\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}