{"id":7055,"date":"2024-11-14T12:00:40","date_gmt":"2024-11-14T04:00:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7055\/"},"modified":"2024-11-14T12:00:40","modified_gmt":"2024-11-14T04:00:40","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-vue-js-%e8%8e%b7%e5%8f%96%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7%e7%9a%84%e6%96%87%e7%ab%a0%e5%88%97%e8%a1%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7055\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Vue.js \u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684\u6587\u7ae0\u5217\u8868\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173036431233221.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 Vue.js \u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684\u6587\u7ae0\u5217\u8868\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 Vue.js \u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684\u6587\u7ae0\u5217\u8868\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u524d\u7aef\u6839\u636e\u767b\u5f55\u7528\u6237\u83b7\u53d6\u81ea\u5df1\u7684\u6587\u7ae0<\/strong><\/p>\n<p>\u5f53\u540e\u7aef\u63d0\u4f9b\u83b7\u53d6\u7528\u6237\u6587\u7ae0\u5217\u8868\u7684\u8def\u7531\u548c\u5904\u7406\u51fd\u6570\u540e\uff0c\u524d\u7aef\u9700\u8981\u5b9e\u73b0\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684 id<\/strong><\/p>\n<ul>\n<li>\u4ece\u540e\u7aef api \u6216\u672c\u5730\u5b58\u50a8\u4e2d\u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684 id\u3002<\/li>\n<li>\u5982\u679c\u4fe1\u606f\u5b58\u50a8\u5728 x \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 this.$store.state \u83b7\u53d6\u7528\u6237 id\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6784\u5efa\u8bf7\u6c42<\/strong><\/p>\n<ul>\n<li>\u6839\u636e\u83b7\u5f97\u7684 id \u6784\u5efa\u4e00\u4e2a\u8bf7\u6c42\u5bf9\u8c61\uff0c\u5305\u62ec\u7528\u6237 id \u548c\u5176\u4ed6\u5fc5\u9700\u7684\u53c2\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u53d1\u9001\u8bf7\u6c42<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u4f7f\u7528 axios \u6216\u5176\u4ed6 http \u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u5230\u540e\u7aef\u8def\u7531\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u54cd\u5e94<\/strong><\/p>\n<ul>\n<li>\u6839\u636e\u540e\u7aef\u8fd4\u56de\u7684\u54cd\u5e94\u66f4\u65b0\u524d\u7aef\u72b6\u6001\uff0c\u4f8b\u5982\u663e\u793a\u7528\u6237\u6587\u7ae0\u5217\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b<\/strong><\/p>\n<pre>\/\/ \u5047\u8bbe\u7528\u6237 ID \u5b58\u50a8\u5728 Vuex \u4e2d\nconst userId = this.$store.state.user.id;\n\n\/\/ \u6784\u5efa\u8bf7\u6c42\nconst request = {\n  userId: userId,\n  \/\/ \u5176\u4ed6\u5fc5\u9700\u7684\u53c2\u6570\n};\n\n\/\/ \u53d1\u9001\u8bf7\u6c42\naxios.post('\/api\/articles', request)\n  .then((response) =&gt; {\n    \/\/ \u66f4\u65b0\u524d\u7aef\u72b6\u6001\n    this.articles = response.data;\n  })\n  .catch((error) =&gt; {\n    \/\/ \u5904\u7406\u9519\u8bef\n  });<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 Vue.js \u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684\u6587\u7ae0\u5217\u8868\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7aef\u6839\u636e\u767b\u5f55\u7528\u6237\u83b7\u53d6\u81ea\u5df1\u7684\u6587\u7ae0 \u5f53\u540e\u7aef\u63d0\u4f9b\u83b7\u53d6\u7528\u6237\u6587\u7ae0\u5217\u8868\u7684\u8def\u7531\u548c\u5904\u7406\u51fd\u6570\u540e\uff0c\u524d\u7aef\u9700\u8981\u5b9e\u73b0\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684 id \u4ece\u540e\u7aef api \u6216\u672c\u5730\u5b58\u50a8\u4e2d\u83b7\u53d6\u767b\u5f55\u7528\u6237\u7684 id\u3002 \u5982\u679c\u4fe1\u606f\u5b58\u50a8\u5728 x \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 this.$store.state \u83b7\u53d6\u7528\u6237 id\u3002 \u6784\u5efa\u8bf7\u6c42 \u6839\u636e\u83b7\u5f97\u7684 id \u6784\u5efa\u4e00\u4e2a\u8bf7\u6c42\u5bf9\u8c61\uff0c\u5305\u62ec\u7528\u6237 id \u548c\u5176\u4ed6\u5fc5\u9700\u7684\u53c2\u6570\u3002 \u53d1\u9001\u8bf7\u6c42 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4f7f\u7528 axios \u6216\u5176\u4ed6 http \u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u5230\u540e\u7aef\u8def\u7531\u3002 \u5904\u7406\u54cd\u5e94 \u6839\u636e\u540e\u7aef\u8fd4\u56de\u7684\u54cd\u5e94\u66f4\u65b0\u524d\u7aef\u72b6\u6001\uff0c\u4f8b\u5982\u663e\u793a\u7528\u6237\u6587\u7ae0\u5217\u8868\u3002 \u4ee3\u7801\u793a\u4f8b \/\/ \u5047\u8bbe\u7528\u6237 ID \u5b58\u50a8\u5728 Vuex \u4e2d const userId = this.$store.state.user.id; \/\/ \u6784\u5efa\u8bf7\u6c42 const request = { userId: userId, \/\/ \u5176\u4ed6\u5fc5\u9700\u7684\u53c2\u6570 }; \/\/ \u53d1\u9001\u8bf7\u6c42 axios.post(&#8216;\/api\/articles&#8217;, request) [&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-7055","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7055","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=7055"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7055\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}