{"id":5813,"date":"2025-05-30T13:44:48","date_gmt":"2025-06-04T06:19:47","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5813"},"modified":"2025-06-04T13:44:48","modified_gmt":"2025-06-04T06:19:47","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e5%9c%a8vue%e4%b8%ad%e4%bd%bf%e7%94%a8axios%e9%80%b2%e8%a1%8chttp%e8%ab%8b%e6%b1%82","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/vue-js\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e5%9c%a8vue%e4%b8%ad%e4%bd%bf%e7%94%a8axios%e9%80%b2%e8%a1%8chttp%e8%ab%8b%e6%b1%82\/","title":{"rendered":"\u63d0\u5347\u4f60\u7684 Vue.js \u958b\u767c\u6280\u80fd\uff1a\u5168\u65b9\u4f4d\u6307\u5357\u4f7f\u7528 Axios \u9032\u884c HTTP \u8acb\u6c42"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Vue.js, Axios, HTTP \u8acb\u6c42, Web \u958b\u767c, JavaScript, \u524d\u7aef\u958b\u767c\"><\/p>\n<h1>\u63d0\u5347\u4f60\u7684 Vue.js \u958b\u767c\u6280\u80fd\uff1a\u5168\u65b9\u4f4d\u6307\u5357\u4f7f\u7528 Axios \u9032\u884c HTTP \u8acb\u6c42<\/h1>\n<p>\u5728\u7576\u4eca\u7684 Web \u958b\u767c\u4e2d\uff0cVue.js \u88ab\u5ee3\u6cdb\u61c9\u7528\u65bc\u69cb\u5efa\u9ad8\u6548\u7684\u7528\u6236\u754c\u9762\uff0c\u800c Axios \u662f\u4e00\u500b\u5f37\u5927\u7684 HTTP \u8acb\u6c42\u5eab\uff0c\u80fd\u5920\u8f15\u9b06\u5730\u8207 API \u9032\u884c\u4ea4\u4e92\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528 Axios \u4f86\u767c\u9001\u5404\u7a2e HTTP \u8acb\u6c42\uff0c\u4e26\u63d0\u4f9b\u5be6\u7528\u7684\u7bc4\u4f8b\u548c\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2>\u70ba\u4ec0\u9ebc\u9078\u64c7 Axios\uff1f<\/h2>\n<p>Axios \u662f\u4e00\u500b\u57fa\u65bc Promise \u7684 HTTP \u5ba2\u6236\u7aef\uff0c\u5177\u6709\u4ee5\u4e0b\u512a\u52e2\uff1a<br \/>\n&#8211; \u7c21\u55ae\u6613\u7528\u7684 API<br \/>\n&#8211; \u652f\u6301\u8acb\u6c42\u548c\u97ff\u61c9\u7684\u6514\u622a<br \/>\n&#8211; \u81ea\u52d5\u8f49\u63db JSON \u6578\u64da<br \/>\n&#8211; \u652f\u6301\u53d6\u6d88\u8acb\u6c42<br \/>\n&#8211; \u5728 Node.js \u548c\u700f\u89bd\u5668\u4e2d\u904b\u884c\u826f\u597d<\/p>\n<h2>\u5b89\u88dd Axios<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u6211\u5011\u9700\u8981\u5148\u5b89\u88dd Axios\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 npm \u6216 yarn \u4f86\u5b89\u88dd\uff1a<\/p>\n<pre class=\"brush: python\">\nnpm install axios\n# \u6216\u8005\nyarn add axios\n<\/pre>\n<h2>\u5728 Vue.js \u4e2d\u5c0e\u5165 Axios<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u6211\u5011\u9700\u8981\u5728 Vue.js \u7d44\u4ef6\u4e2d\u5f15\u5165 Axios\uff1a<\/p>\n<pre class=\"brush: python\">\nimport axios from 'axios';\n<\/pre>\n<h2>\u767c\u9001 HTTP GET \u8acb\u6c42<\/h2>\n<p>\u4f7f\u7528 `axios.get()` \u65b9\u6cd5\u8f15\u9b06\u767c\u9001 HTTP GET \u8acb\u6c42\uff1a<\/p>\n<pre class=\"brush: python\">\naxios.get('\/api\/user?ID=12345')\n  .then(response => {\n    console.log('\u7528\u6236\u8cc7\u6599:', response.data);\n  })\n  .catch(error => {\n    console.error('\u51fa\u932f\u4e86:', error);\n  });\n<\/pre>\n<h2>\u767c\u9001 HTTP POST \u8acb\u6c42<\/h2>\n<p>\u6211\u5011\u4e5f\u53ef\u4ee5\u4f7f\u7528 `axios.post()` \u65b9\u6cd5\u4f86\u767c\u9001 HTTP POST \u8acb\u6c42\uff1a<\/p>\n<pre class=\"brush: python\">\naxios.post('\/api\/user', {\n    firstName: 'Fred',\n    lastName: 'Flintstone'\n  })\n  .then(response => {\n    console.log('\u7528\u6236\u5275\u5efa\u6210\u529f:', response.data);\n  })\n  .catch(error => {\n    console.error('\u51fa\u932f\u4e86:', error);\n  });\n<\/pre>\n<h2>\u767c\u9001 HTTP PUT \u8acb\u6c42<\/h2>\n<p>\u4f7f\u7528 `axios.put()` \u65b9\u6cd5\u4f86\u66f4\u65b0\u73fe\u6709\u8cc7\u6e90\uff1a<\/p>\n<pre class=\"brush: python\">\naxios.put('\/api\/user\/12345', {\n    firstName: 'Fred',\n    lastName: 'Flintstone'\n  })\n  .then(response => {\n    console.log('\u7528\u6236\u66f4\u65b0\u6210\u529f:', response.data);\n  })\n  .catch(error => {\n    console.error('\u51fa\u932f\u4e86:', error);\n  });\n<\/pre>\n<h2>\u767c\u9001 HTTP DELETE \u8acb\u6c42<\/h2>\n<p>\u6700\u5f8c\uff0c\u4f7f\u7528 `axios.delete()` \u65b9\u6cd5\u4f86\u522a\u9664\u8cc7\u6e90\uff1a<\/p>\n<pre class=\"brush: python\">\naxios.delete('\/api\/user\/12345')\n  .then(response => {\n    console.log('\u7528\u6236\u522a\u9664\u6210\u529f:', response.data);\n  })\n  .catch(error => {\n    console.error('\u51fa\u932f\u4e86:', error);\n  });\n<\/pre>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5b78\u7fd2\u4e86\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528 Axios \u9032\u884c HTTP \u8acb\u6c42\u3002\u5f9e\u5b89\u88dd\u5230\u5be6\u969b\u4f7f\u7528\u5404\u7a2e\u8acb\u6c42\u65b9\u6cd5\uff0cAxios \u4f7f\u5f97\u8207 API \u7684\u4ea4\u4e92\u8b8a\u5f97\u7c21\u55ae\u800c\u9ad8\u6548\u3002\u7121\u8ad6\u662f GET\u3001POST\u3001PUT \u9084\u662f DELETE \u8acb\u6c42\uff0c\u60a8\u90fd\u53ef\u4ee5\u8f15\u9b06\u5730\u5728 Vue.js \u61c9\u7528\u4e2d\u5be6\u73fe\u3002<\/p>\n<p>\u638c\u63e1\u9019\u4e9b\u57fa\u672c\u64cd\u4f5c\u5f8c\uff0c\u60a8\u5c07\u80fd\u5920\u5728 Vue.js \u9805\u76ee\u4e2d\u9748\u6d3b\u5730\u4f7f\u7528 Axios\uff0c\u9032\u4e00\u6b65\u63d0\u5347\u60a8\u7684 Web \u958b\u767c\u6280\u80fd\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728Vue\u4e2d\u4f7f\u7528Axios\u9032\u884cHTTP\u8acb\u6c42\uff0cAxios\u662f\u4e00\u500b\u57fa\u65bcPromise\u7684HTTP\u5ba2\u6236\u7aef\uff0c\u53ef\u4ee5\u7528\u65bc\u767c\u9001\u8acb\u6c42\u548c\u63a5\u6536\u54cd\u61c9\uff0c\u4e26\u63d0\u4f9b\u4e86\u8a31\u591a\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u60a8\u66f4\u8f15\u9b06\u5730\u7ba1\u7406HTTP\u8acb\u6c42\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[180,179],"tags":[178,177],"class_list":["post-5813","post","type-post","status-publish","format-standard","hentry","category-vue","category-vue-js","tag-vue","tag-vue-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1vL","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5813"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5813\/revisions"}],"predecessor-version":[{"id":5814,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5813\/revisions\/5814"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}