{"id":524,"date":"2023-12-18T09:25:31","date_gmt":"2023-12-18T01:25:31","guid":{"rendered":"http:\/\/ericw.top\/?p=524"},"modified":"2023-12-18T09:25:31","modified_gmt":"2023-12-18T01:25:31","slug":"%e5%bc%80%e5%a7%8b%e4%bd%bf%e7%94%a8-vue","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=524","title":{"rendered":"\u5f00\u59cb\u4f7f\u7528 Vue"},"content":{"rendered":"<h1 id=\"toc-0\">\u5f00\u59cb\u4f7f\u7528 Vue<\/h1>\n<p>Vue \u662f\u4e00\u4e2a\u7528\u4e8e<strong>\u6784\u5efa\u7528\u6237\u754c\u9762<\/strong>\u7684<strong>\u6e10\u8fdb\u5f0f\u6846\u67b6<\/strong><\/p>\n<p><strong>\u6784\u5efa\u7528\u6237\u754c\u9762\uff1a\u57fa\u4e8e \u6570\u636e \u52a8\u6001 \u6e32\u67d3 \u9875\u9762<\/strong><\/p>\n<p>\u2460 Vue \u6838\u5fc3\u5305\u5f00\u53d1 <\/p>\n<p>\u573a\u666f\uff1a\u5c40\u90e8 \u6a21\u5757\u6539\u9020 <\/p>\n<p>\u2461 Vue \u6838\u5fc3\u5305 &amp; Vue \u63d2\u4ef6 \u5de5\u7a0b\u5316\u5f00\u53d1 <\/p>\n<p>\u573a\u666f\uff1a\u6574\u7ad9 \u5f00\u53d1<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702862700789-300x156.png\" alt=\"\" \/><\/p>\n<h2 id=\"toc-1\">Vue \u7b80\u4ecb<\/h2>\n<p><strong>Vue \u662f\u4e00\u4e2a\u73b0\u4ee3 JavaScript \u6846\u67b6\u63d0\u4f9b\u4e86\u6709\u7528\u7684\u8bbe\u65bd\u6e10\u8fdb\u589e\u5f3a<\/strong>\u2014\u2014\u4e0d\u50cf\u8bb8\u591a\u5176\u4ed6\u6846\u67b6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <strong>Vue \u589e\u5f3a\u73b0\u6709\u7684 HTML<\/strong>\u3002<\/p>\n<p>\u8bdd\u867d\u5982\u6b64\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 <strong>Vue \u7f16\u5199\u5b8c\u6574\u7684\u5355\u9875\u5e94\u7528\u7a0b\u5e8f\uff08SPA\uff09<\/strong>\u3002\u8fd9\u5141\u8bb8\u4f60\u521b\u5efa\u5b8c\u5168\u7531 Vue \u7ba1\u7406\u7684\u6807\u8bb0\uff0c\u5f53\u5904\u7406\u590d\u6742\u5e94\u7528\u7a0b\u5e8f\u65f6\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u4eba\u5458\u7684\u4f53\u9a8c\u548c\u6027\u80fd\u3002\u5b83\u8fd8\u5141\u8bb8\u4f60\u5728\u9700\u8981\u65f6\u5229\u7528\u7528\u4e8e\u5ba2\u6237\u7aef\u8def\u7531\u548c\u72b6\u6001\u7ba1\u7406\u7684\u5e93\u3002<\/p>\n<p>\u9664\u4e86\u5141\u8bb8\u4f60\u9010\u6b65\u5c06 Vue \u96c6\u6210\u5230\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c<strong>Vue \u8fd8\u63d0\u4f9b\u4e86\u4e00\u79cd\u6e10\u8fdb\u7684\u65b9\u5f0f\u7f16\u5199\u6807\u8bb0<\/strong>\u3002\u50cf\u5927\u591a\u6570\u6846\u67b6\uff0cVue \u901a\u8fc7\u7ec4\u4ef6\u5141\u8bb8\u4f60\u521b\u5efa\u53ef\u91cd\u7528\u5757\u6807\u8bb0\u3002\u5927\u591a\u6570\u65f6\u5019\uff0c<strong>Vue \u7ec4\u4ef6\u662f\u4f7f\u7528\u4e00\u4e2a\u7279\u6b8a\u7684 HTML \u6a21\u677f\u7684\u8bed\u6cd5\u5199\u7684<\/strong>\u3002<\/p>\n<h2 id=\"toc-2\">\u5b89\u88c5Vue<\/h2>\n<p>\u8981\u5728\u73b0\u6709\u7ad9\u70b9\u4e2d\u4f7f\u7528 Vue\uff0c\u53ef\u4ee5<strong>\u901a\u8fc7<code class=\"prettyprint\" >&lt;script&gt;<\/code> \u5143\u7d20\u5728\u9875\u9762\u4e2d\u4f7f\u7528<\/strong>\u3002\u8fd9\u4f7f\u4f60\u53ef\u4ee5\u5f00\u59cb\u5728\u73b0\u6709\u7ad9\u70b9\u4e0a\u4f7f\u7528 Vue\uff0c\u8fd9\u5c31\u662f Vue \u5f15\u4ee5\u4e3a\u50b2\u7684\u6e10\u8fdb\u5f0f\u6846\u67b6\u7684\u539f\u56e0\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 Vue \u7684\u8bb8\u591a\u6838\u5fc3\u529f\u80fd\uff0c\u4f8b\u5982<strong>\u5c5e\u6027\u3001\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u548c\u6570\u636e\u7ba1\u7406<\/strong>\u3002<\/p>\n<ul>\n<li>\u5f00\u53d1\u73af\u5883\u7248\u672c\uff0c\u5305\u542b\u4e86\u6709\u5e2e\u52a9\u7684\u547d\u4ee4\u884c\u8b66\u544a<\/li>\n<\/ul>\n<pre><code class=\"prettyprint\"  class=\"language-html\">&lt;script src=&quot;https:\/\/unpkg.com\/vue@3\/dist\/vue.global.js&quot;&gt;&lt;\/script&gt;<\/code><\/pre>\n<ul>\n<li>\u751f\u4ea7\u73af\u5883\u7248\u672c\uff0c\u4f18\u5316\u4e86\u5c3a\u5bf8\u548c\u901f\u5ea6\uff0c\u5efa\u8bae\u4f60\u5728\u7ad9\u70b9\u4e0a\u5305\u542bVue\u65f6\u6307\u5b9a\u7248\u672c\u53f7\uff0c\u8fd9\u6837\u4efb\u4f55\u6846\u67b6\u66f4\u65b0\u90fd\u4e0d\u4f1a\u5f71\u54cd\u4f60\u7684\u7f51\u7ad9<\/li>\n<\/ul>\n<pre><code class=\"prettyprint\"  class=\"language-html\">&lt;script src=&quot;https:\/\/unpkg.com\/vue@3\/dist\/vue.global.prod.js&quot;&gt;&lt;\/script&gt;<\/code><\/pre>\n<p>\u7136\u800c\uff0c\u8fd9\u79cd\u65b9\u6cd5\u6709\u4e00\u4e9b<strong>\u5c40\u9650\u6027<\/strong>\u3002<strong>\u8981\u6784\u5efa\u66f4\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f60\u9700\u8981\u4f7f\u7528 Vue NPM package<\/strong>\u3002\u8fd9\u5c06\u5141\u8bb8\u4f60\u4f7f\u7528 Vue \u7684\u9ad8\u7ea7\u529f\u80fd\u5e76\u5229\u7528 WebPack \u7b49\u6346\u7ed1\u5305\u3002\u4e3a\u4e86\u4f7f\u4f7f\u7528 Vue \u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u66f4\u5bb9\u6613\uff0c\u6709\u4e00\u4e2a <strong>CLI \u6765\u7b80\u5316\u5f00\u53d1\u8fc7\u7a0b<\/strong>\u3002<strong>\u8981\u4f7f\u7528 npm \u8f6f\u4ef6\u5305\u548c CLI<\/strong>:<\/p>\n<p>1\u3001\u5b89\u88c5Node.js 8.11\u53ca\u4ee5\u4e0a\u7684\u7248\u672c<\/p>\n<p>2\u3001npm\u6216yarn<\/p>\n<p>\u5b89\u88c5CLI\uff0c\u7ec8\u7aef\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>npm\uff1a<\/p>\n<pre><code class=\"prettyprint\" >npm install --global @vue\/cli<\/code><\/pre>\n<p>yarn\uff1a<\/p>\n<pre><code class=\"prettyprint\" >yarn global add @vue\/cli<\/code><\/pre>\n<h2 id=\"toc-3\">\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u9879\u76ee<\/h2>\n<p>\u4e3a\u4e86\u63a2\u7d22 Vue \u4e2d\u5404\u79cd\u5404\u6837\u7684\u7279\u5f81\uff0c<strong>\u6211\u4eec\u5c06\u5efa\u7acb\u4e00\u4e2a\u7b80\u5355\u7684\u4efb\u52a1\u6e05\u5355\u5e94\u7528<\/strong>\u3002<strong>\u6211\u4eec\u5c06\u4f1a\u4f7f\u7528 Vue \u811a\u624b\u67b6\u5de5\u5177<\/strong>\u53bb\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5e94\u7528\u6846\u67b6\u5e76\u5728\u4e0a\u9762\u642d\u5efa\u6211\u4eec\u7684\u5e94\u7528\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\uff0c<strong>\u7528 <code class=\"prettyprint\" >cd<\/code> \u547d\u4ee4\u8fdb\u5165\u4f60\u60f3\u8981\u521b\u5efa\u793a\u4f8b\u7684\u6587\u4ef6\u5939<\/strong>\uff0c\u7136\u540e\u6267\u884c <code class=\"prettyprint\" >vue create moz-todo-vue<\/code>\u3002\u4f60\u53ef\u4ee5\u9009\u62e9\u9ed8\u8ba4\u9009\u9879 <code class=\"prettyprint\" >Default ([Vue 3] babel, eslint)<\/code> \u7136\u540e\u6309\u4e0b\u952e\u76d8\u4e0a\u7684 Enter \u7ee7\u7eed\u3002<strong>CLI \u73b0\u5728\u5c06\u5f00\u59cb\u6784\u5efa\u4f60\u7684\u9879\u76ee\uff0c\u5e76\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u9879<\/strong>\u3002<\/p>\n<p><strong>\u7136\u540e\u811a\u624b\u67b6\u5de5\u5177\u5c31\u5f00\u59cb\u6784\u5efa\u9879\u76ee\uff0c\u5e76\u4e14\u5b89\u88c5\u6240\u9700\u7684\u4f9d\u8d56<\/strong>\u3002<\/p>\n<p>\u5982\u679c\u4f60\u4ee5\u524d\u4ece\u672a\u8fd0\u884c\u8fc7 Vue CLI\uff0c\u5219\u4f1a\u518d\u6709\u4e00\u4e2a\u95ee\u9898\u2014\u2014\u4f60\u5c06\u88ab\u8981\u6c42\u9009\u62e9\u4e00\u4e2a\u5305\u7ba1\u7406\u5668\uff0c\u5b83\u9ed8\u8ba4\u4e3a yarn\u3002\u4ece\u73b0\u5728\u5f00\u59cb\uff0cVue CLI \u5c06\u9ed8\u8ba4\u4f7f\u7528\u6b64\u5305\u7ba1\u7406\u5668\u3002\u5982\u679c\u4f60\u6b64\u540e\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684\u5305\u7ba1\u7406\u5668\uff0c\u5219\u53ef\u4ee5\u5728\u8fd0\u884c <code class=\"prettyprint\" >vue create<\/code> \u65f6\u4f20\u5165\u53c2\u6570 <code class=\"prettyprint\" >--packageManager=&lt;package-manager&gt;<\/code>\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u60f3\u8981\u4f7f\u7528 <code class=\"prettyprint\" >npm<\/code> \u521b\u5efa <code class=\"prettyprint\" >moz-todo-vue<\/code> \u9879\u76ee\uff0c\u5e76\u4e14\u4e4b\u524d\u9009\u62e9\u4e86 <code class=\"prettyprint\" >yarn<\/code>\uff0c\u5219\u5e94\u8fd0\u884c <code class=\"prettyprint\" >vue create moz-todo-vue --packageManager=npm<\/code>\u3002<\/p>\n<h2 id=\"toc-4\">\u9879\u76ee\u7ed3\u6784<\/h2>\n<ul>\n<li>\n<p><code class=\"prettyprint\" >package.json<\/code>\uff1a\u8be5\u6587\u4ef6\u5305\u542b\u9879\u76ee\u7684\u4f9d\u8d56\u9879\u5217\u8868\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5143\u6570\u636e\u548c <code class=\"prettyprint\" >eslint<\/code> \u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >yarn.lock<\/code>\uff1a\u5982\u679c\u4f60\u9009\u62e9 <code class=\"prettyprint\" >yarn<\/code> \u4f5c\u4e3a\u4f60\u7684\u5305\u7ba1\u7406\u5668\uff0c\u5c06\u751f\u6210\u6b64\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u4f9d\u8d56\u9879\u548c\u5b50\u4f9d\u8d56\u9879\u7684\u5217\u8868\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >babel.config.js<\/code>\uff1a\u8fd9\u4e2a\u662f Babel\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u5728\u5f00\u53d1\u4e2d\u4f7f\u7528 JavaScript \u7684\u65b0\u7279\u6027\uff0c\u5e76\u4e14\u5c06\u5176\u8f6c\u6362\u4e3a\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u53ef\u4ee5\u8de8\u6d4f\u89c8\u5668\u8fd0\u884c\u7684\u65e7\u8bed\u6cd5\u4ee3\u7801\u3002\u4f60\u4e5f\u53ef\u4ee5\u5728\u8fd9\u4e2a\u91cc\u914d\u7f6e\u989d\u5916\u7684 babel \u63d2\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >jsconfig.json<\/code>\uff1a\u8fd9\u662f\u4e00\u4efd\u7528\u4e8e Visual Studio Code\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5b83\u4e3a VS Code \u63d0\u4f9b\u4e86\u5173\u4e8e\u9879\u76ee\u7ed3\u6784\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\uff0c\u5e76\u5e2e\u52a9\u81ea\u52a8\u5b8c\u6210\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >public<\/code>\u8fd9\u4e2a\u76ee\u5f55\u5305\u542b\u4e00\u4e9b\u5728Webpack\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u52a0\u5de5\u5904\u7406\u8fc7\u7684\u6587\u4ef6\uff08\u6709\u4e00\u4e2a\u4f8b\u5916\uff1aindex.html \u4f1a\u6709\u4e00\u4e9b\u5904\u7406\uff09\u3002<\/p>\n<ul>\n<li>\n<p><code class=\"prettyprint\" >favicon.ico<\/code>\uff1a\u8fd9\u4e2a\u662f\u9879\u76ee\u7684\u56fe\u6807\uff0c\u5f53\u524d\u5c31\u662f\u4e00\u4e2a Vue \u7684 logo\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >index.html<\/code>\uff1a\u8fd9\u662f\u5e94\u7528\u7684\u6a21\u677f\u6587\u4ef6\uff0cVue \u5e94\u7528\u4f1a\u901a\u8fc7\u8fd9\u4e2a HTML \u9875\u9762\u6765\u8fd0\u884c\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7 lodash \u8fd9\u79cd\u6a21\u677f\u8bed\u6cd5\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc\u63d2\u503c\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >src<\/code>\uff1a\u8fd9\u4e2a\u662f Vue \u5e94\u7528\u7684\u6838\u5fc3\u4ee3\u7801\u76ee\u5f55<\/p>\n<ul>\n<li>\n<p><code class=\"prettyprint\" >main.js<\/code>\uff1a\u8fd9\u662f\u5e94\u7528\u7684\u5165\u53e3\u6587\u4ef6\u3002\u76ee\u524d\u5b83\u4f1a\u521d\u59cb\u5316 Vue \u5e94\u7528\u5e76\u4e14\u5236\u5b9a\u5c06\u5e94\u7528\u6302\u8f7d\u5230 <code class=\"prettyprint\" >index.html<\/code> \u6587\u4ef6\u4e2d\u7684\u54ea\u4e2a HTML \u5143\u7d20\u4e0a\u3002\u901a\u5e38\u8fd8\u4f1a\u505a\u4e00\u4e9b\u6ce8\u518c\u5168\u5c40\u7ec4\u4ef6\u6216\u8005\u6dfb\u989d\u5916\u7684 Vue \u5e93\u7684\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >App.vue<\/code>\uff1a\u8fd9\u662f Vue \u5e94\u7528\u7684\u6839\u8282\u70b9\u7ec4\u4ef6\uff0c\u5f80\u4e0b\u770b\u53ef\u4ee5\u4e86\u89e3\u66f4\u591a\u5173\u6ce8 Vue \u7ec4\u4ef6\u7684\u4fe1\u606f\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >components<\/code>\uff1a\u8fd9\u662f\u7528\u6765\u5b58\u653e\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u76ee\u5f55\uff0c\u76ee\u524d\u91cc\u9762\u4f1a\u6709\u4e00\u4e2a\u793a\u4f8b\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p><code class=\"prettyprint\" >assets<\/code>\uff1a\u8fd9\u4e2a\u76ee\u5f55\u7528\u6765\u5b58\u653e\u50cf CSS\u3001\u56fe\u7247\u8fd9\u79cd\u9759\u6001\u8d44\u6e90\uff0c\u4f46\u662f\u56e0\u4e3a\u5b83\u4eec\u5c5e\u4e8e\u4ee3\u7801\u76ee\u5f55\u4e0b\uff0c\u6240\u4ee5\u53ef\u4ee5\u7528 webpack \u6765\u64cd\u4f5c\u548c\u5904\u7406\u3002\u610f\u601d\u5c31\u662f\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u9884\u5904\u7406\u6bd4\u5982 Sass\/SCSS\u6216\u8005 Stylus\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5f00\u59cb\u4f7f\u7528 Vue Vue \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa\u7528\u6237\u754c\u9762\u7684\u6e10\u8fdb\u5f0f\u6846\u67b6 \u6784\u5efa\u7528\u6237\u754c\u9762\uff1a\u57fa\u4e8e \u6570\u636e \u52a8\u6001 \u6e32\u67d3 \u9875\u9762 \u2460  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":525,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,11,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/524"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=524"}],"version-history":[{"count":1,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/524\/revisions"}],"predecessor-version":[{"id":526,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/524\/revisions\/526"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/525"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=524"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}