{"id":295988,"date":"2021-01-19T20:01:13","date_gmt":"2021-01-19T12:01:13","guid":{"rendered":"http:\/\/4563.org\/?p=295988"},"modified":"2021-01-19T20:01:13","modified_gmt":"2021-01-19T12:01:13","slug":"%e5%9c%a8-vue-%e7%9a%84%e5%8e%9f%e5%9e%8b%e4%b8%8a%e6%b3%a8%e5%85%a5%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%ef%bc%8c%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e9%80%9a%e8%bf%87%e5%bc%82%e6%ad%a5-http-%e8%ae%bf","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=295988","title":{"rendered":"\u5728 vue \u7684\u539f\u578b\u4e0a\u6ce8\u5165\u914d\u7f6e\u6587\u4ef6\uff0c\u914d\u7f6e\u6587\u4ef6\u901a\u8fc7\u5f02\u6b65 http \u8bbf\u95ee\u83b7\u53d6\uff0c\u5982\u4f55\u63a7\u5236\u521d\u59cb\u5316\u987a\u5e8f\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5728 vue \u7684\u539f\u578b\u4e0a\u6ce8\u5165\u914d\u7f6e\u6587\u4ef6\uff0c\u914d\u7f6e\u6587\u4ef6\u901a\u8fc7\u5f02\u6b65 http \u8bbf\u95ee\u83b7\u53d6\uff0c\u5982\u4f55\u63a7\u5236\u521d\u59cb\u5316\u987a\u5e8f\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : darknoll <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4f7f\u7528\u7684\u811a\u624b\u67b6\u662f vue-cli4, \u73b0\u5728\u9700\u6c42\u662f\u8fd9\u6837\u7684\uff0c\u8981\u5b9e\u73b0\u524d\u7aef\u7684\u53ef\u914d\u7f6e\u5316\uff0c\u6bd4\u5982 axios \u8bbf\u95ee\u7684 http \u5730\u5740\u53ef\u914d\u7f6e\uff0c\u8fd9\u6837\u5c31\u5728 public \u6587\u4ef6\u5939\u4e2d\u589e\u52a0\u4e00\u4e2a config \u7684\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u4e13\u95e8\u653e\u4e00\u4e9b json \u914d\u7f6e\u6587\u4ef6\u3002 \u56e0\u4e3a\u8981\u5728 js \u6587\u4ef6\u4e2d\u8bbf\u95ee\u8fd9\u4e9b\u5168\u5c40\u914d\u7f6e\uff0c\u6240\u4ee5\u6211\u6253\u7b97\u628a\u8fd9\u4e9b\u914d\u7f6e\u6302\u8f7d\u5230 vue \u7684\u539f\u578b\uff0c\u7136\u540e\u5728 main.js \u4e2d\u8fd9\u6837\u505a !(async () =&gt; { await axios.get(&#8216;configs.json&#8217;).then(response =&gt; { Vue.prototype.$config = response.data }) })()<\/p>\n<p>new Vue({ router, store, render: h =&gt; h(App) }).$mount(&#8216;#app&#8217;)<\/p>\n<p>\u90a3\u4e48\u6211\u73b0\u5728\u6709\u4e2a\u95ee\u9898\uff0c\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u4f53\u79ef\u8fc7\u5927\uff0c\u5bfc\u81f4\u5728\u5176\u4ed6 js \u4f7f\u7528\u914d\u7f6e\u9879\u7684\u65f6\u5019\u8fd8\u6ca1\u6709\u8fd4\u56de\uff0c\u5e94\u8be5\u600e\u4e48\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\uff1f\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u6700\u597d\u628a\u83b7\u53d6 configs.json \u540c\u6b65\u5316\uff0c\u4e0d\u9700\u8981\u5f02\u6b65\u83b7\u53d6\u914d\u7f6e\u6587\u4ef6\uff0c\u4f46\u662f\u8bbf\u95ee public \u4e2d\u7684\u4e1c\u897f\u53c8\u6ca1\u529e\u6cd5\u76f4\u63a5 import\uff0c\u6709\u6ca1\u6709\u5565\u597d\u7684\u65b9\u6848\u5904\u7406\u8fd9\u79cd\u60c5\u666f\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>13<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4974127\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : YuxiangLuo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u628a new Vue \u4e5f\u653e\u5230 axios \u8bf7\u6c42\u7684 callback \u91cc\u4e0d\u5c31\u597d\u4e86<\/p>\n<p>\u8fd8\u6709\u4f60\u8fd9\u4e2a<br \/> !(async () =&gt; { await axios.get(&#8216;configs.json&#8217;).then(response =&gt; { Vue.prototype.$config = response.data }) })()<br \/>\u5199\u5f97\u597d\u5947\u602a\uff0c\u611f\u53f9\u53f7\u662f\u4ec0\u4e48\u610f\u601d\uff0c\u7528\u4e86 async\/await \u4e3a\u4ec0\u4e48\u8fd8\u8981\u7528 then<br \/>\u6362\u6210 axios.get(&#8216;configs.json&#8217;).then(response =&gt; { Vue.prototype.$config = response.data })\u90fd\u6ca1\u6709\u533a\u522b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974128\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : azcvcza <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90a3\u5c31\u518d\u63a5\u4e00\u4e2a then\uff0c\u628a new Vue \u90a3\u884c\u653e\u5230\u91cc\u8fb9\u53bb\u55bd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974129\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : darknoll <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @YuxiangLuo \u5306\u5fd9\u4e4b\u95f4\u5199\u9519\u4e86\uff0c\u5e94\u8be5\u628a await \u53bb\u6389\uff0c\u524d\u9762\u611f\u53f9\u53f7\u662f\u9632\u6b62 eslint \u62a5\u9519                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974130\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : coderfuns <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8fd9\u601d\u8def\u6709\u95ee\u9898\uff0c\u914d\u7f6e\u5316\u7684\u6587\u4ef6\u53ef\u4ee5\u501f\u52a9 babel\uff0cwebpack \u5728\u6784\u5efa\u7684\u65f6\u5019\u5c31\u6ce8\u5165\uff0c\u4e3a\u4ec0\u4e48\u8981\u5728\u4ee3\u7801\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\u6ce8\u5165\u5462\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974131\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wunonglin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \uff1f\uff1f\uff1f\u4f60\u662f\u60f3\u505a\u6210\u914d\u7f6e\u4e2d\u5fc3\u90a3\u6837\u8fd8\u662f\u73af\u5883\u53d8\u91cf\u90a3\u6837\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974132\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6784\u5efa\u65f6\u6ce8\u5165\u4e00\u4e2a\u57fa\u672c\u7684\uff0c\u524d\u7aef\u53ea\u8bf7\u6c42\u786e\u8ba4\u5dee\u91cf\u3002<br \/>\u5982\u679c\u4ecd\u7136\u62c5\u5fc3\u5dee\u91cf\u5de8\u5927\uff0c\u6211\u89c9\u5f97\u4f60\u4eec\u5e94\u8be5\u7ed9\u524d\u7aef\u53d1\u5e03\u65b0\u7248\u672c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974133\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 code splitting point \u5c06\u8fd9\u4e2a config.json \u6253\u5305\u6210\u5355\u72ec\u7684 dist\/conf.js \uff0c\u4f5c\u4e3a\u9759\u6001\u4f9d\u8d56<br \/>\u6709\u66f4\u65b0\u53ef\u4ee5\u76f4\u63a5\u6539 conf.js \u7684\u5185\u5bb9\uff0c\u751a\u81f3\u7531\u540e\u7aef\u6839\u636e\u6a21\u677f\u6784\u9020 conf.js \u7684\u5185\u5bb9\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974134\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : darknoll <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @coderfuns \u4f60\u6253\u5305\u597d\u4e86\u4e4b\u540e\u5c31\u4e00\u6210\u4e0d\u53d8\u4e86\u554a\uff0c\u5982\u679c\u6211\u5df2\u7ecf\u90e8\u7f72\u597d\u7684\u524d\u7aef\uff0c\u6211\u60f3\u6539\u53d8\u540e\u7aef\u63a5\u53e3\u5730\u5740\u4e86\uff0c\u6211\u53ef\u4ee5\u5f00\u59cb\u5c31\u628a\u5b83\u5199\u5230 public \u7684 json \u6587\u4ef6\u91cc\u9762\uff08 public \u91cc\u9762\u7684\u5185\u5bb9 webpack \u662f\u4e0d\u4f1a\u6539\u7684\uff09\uff0c\u7136\u540e\u8981\u6539\u7684\u65f6\u5019\u53d1\u4e2a\u8bf7\u6c42\u8ba9\u540e\u7aef\u4fee\u6539\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974135\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : darknoll <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u8fd9\u4e2a\u600e\u4e48\u5f04\uff0c\u8fd8\u6ca1\u7814\u7a76\u8fc7\uff0c\u6709\u5177\u4f53\u7684\u6559\u7a0b\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974136\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : coderfuns <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @darknoll \u90a3\u8fd9\u4e2a\u5c31\u662f\u914d\u7f6e\u4e2d\u5fc3\u7684\u6982\u5ff5\u4e86\u3002\u5982\u679c\u4f60\u7528\u672c\u5730\u6587\u4ef6\uff0c\u76f4\u63a5\u52a0\u8f7d\u9759\u6001\u6587\u4ef6\u5c31\u53ef\u4ee5\u4e86\u554a\uff0c\u8bd5\u8bd5 systemjs \u52a0\u8f7d json\uff0c\u7c7b\u4f3c jsonp \u65b9\u5f0f\u653e\u7f6e\u5230\u9876\u5c42 window \u4e0a\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974137\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tomcats <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6309\u7167\u4f60\u7684\u9700\u6c42\uff0c\u4f60\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u5fc5\u987b\u5f97\u5148\u52a0\u8f7d\uff0c\u90a3\u4e48\u76f4\u63a5\u4e22 script \u6807\u7b7e\u52a0\u8f7d\u597d\u4e86\uff0c\u5f04\u6210\u5168\u5c40\u53d8\u91cf                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974138\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : linbingcheng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             promise await async \u5f02\u6b65\u53d8\u540c\u6b65\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4974139\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yaphets666 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5bf8\u6570\u636e\u5e93\u4e0d\u5c31\u884c\u4e86?<br \/>\u518d\u8bf4\u4e86,\u524d\u7aef\u662f\u4e0d\u53ef\u914d\u7f6e\u7684.\u8ddf\u6784\u5efa\u76f8\u5173\u7684\u4e1c\u897f\u90fd\u5728\u6253\u5305\u9636\u6bb5\u6253\u8fdb\u53bb\u4e86.\u4e0d\u91cd\u65b0\u6253\u5305\u6539\u4e0d\u4e86.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 vue \u7684\u539f\u578b\u4e0a\u6ce8\u5165\u914d\u7f6e\u6587\u4ef6\uff0c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/295988"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295988"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/295988\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295988"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}