{"id":886,"date":"2024-01-15T09:15:25","date_gmt":"2024-01-15T01:15:25","guid":{"rendered":"http:\/\/ericw.top\/?p=886"},"modified":"2024-01-15T09:15:25","modified_gmt":"2024-01-15T01:15:25","slug":"%e8%b7%af%e7%94%b1%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=886","title":{"rendered":"\u8def\u7531\u5165\u95e8"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"toc-0\">\u5355\u9875\u5e94\u7528\u7a0b\u5e8f: SPA - Single Page Application<\/h2>\n\n\n\n<ul>\n<li><strong>\u5355\u9875\u9762\u5e94\u7528\uff1a<\/strong>\u6240\u6709\u529f\u80fd\u5728\u4e00\u4e2aHTML\u9875\u9762\u4e0a\u5b9e\u73b0<\/li>\n\n\n\n<li><strong>\u4f18\u70b9\uff1a<\/strong>\u6309\u9700\u66f4\u65b0\u6027\u80fd\u9ad8\uff0c\u5f00\u53d1\u6548\u7387\u9ad8\uff0c\u7528\u6237\u4f53\u9a8c\u597d<\/li>\n\n\n\n<li><strong>\u7f3a\u70b9\uff1a<\/strong>\u9996\u5c4f\u52a0\u8f7d\u6ee1\uff0c\u5b66\u4e60\u6210\u672c\u9ad8<\/li>\n\n\n\n<li><strong>\u5e94\u7528\u573a\u666f\uff1a<\/strong>\u7cfb\u7edf\u7c7b\u7f51\u7ad9 \/ \u5185\u90e8\u7f51\u7ad9 \/ \u6587\u6863\u7c7b\u7f51\u7ad9 \/\u79fb\u52a8\u7aef\u7ad9\u70b9<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"385\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-50-1024x385.png\" alt=\"\" class=\"wp-image-887\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-50-1024x385.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-50-300x113.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-50-768x289.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-50.png 1171w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5355\u9875\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e4b\u6240\u4ee5\u5f00\u53d1\u6548\u7387\u9ad8\uff0c\u6027\u80fd\u9ad8\uff0c\u7528\u6237\u4f53\u9a8c\u597d\uff0c\u6700\u5927\u7684\u539f\u56e0\u5c31\u662f\uff1a<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">\u9875\u9762\u6309\u9700\u66f4\u65b0<\/mark><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-1\">\u8def\u7531<\/h2>\n\n\n\n<p>\u751f\u6d3b\u4e2d\u7684\u8def\u7531\uff1a\u8bbe\u5907\u548cip\u7684\u6620\u5c04\u5173\u7cfb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"977\" height=\"487\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-51.png\" alt=\"\" class=\"wp-image-888\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-51.png 977w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-51-300x150.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-51-768x383.png 768w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/figure>\n\n\n\n<p><strong>Vue\u4e2d\u7684\u8def\u7531<\/strong>\uff1a<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\"><strong>\u8def\u5f84<\/strong><\/mark> \u548c <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u7ec4\u4ef6<\/mark> <\/strong>\u7684 <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u6620\u5c04<\/mark><\/strong>\u5173\u7cfb<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"443\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-52-1024x443.png\" alt=\"\" class=\"wp-image-889\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-52-1024x443.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-52-300x130.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-52-768x332.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-52.png 1072w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-2\">VueRouter<\/h2>\n\n\n\n<p>\u4f5c\u7528\uff1a<strong>\u4fee\u6539\u5730\u5740\u680f<\/strong>\u8def\u5f84\u65f6\uff0c\u5207\u6362<strong>\u663e\u793a\u5339\u914d\u7684\u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p>\u5b98\u7f51\uff1a<a href=\"https:\/\/v3.router.vuejs.org\/zh\/\">https:\/\/v3.router.vuejs.org\/zh\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-3\">VueRouter\u7684\u4f7f\u7528 \uff085+2\uff09<\/h2>\n\n\n\n<p>5\u4e2a\u57fa\u7840\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<p>1\u3001\u4e0b\u8f7d\uff0c\u4e0b\u8f7dVueRouter\u6a21\u5757\u5230\u5f53\u524d\u5de5\u7a0b\uff0c\u7248\u672c3.6.5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >npm install vue-router --save<\/code><\/pre>\n\n\n\n<p>2\u3001\u5f15\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >import VueRouter from &#039;vue-router&#039;<\/code><\/pre>\n\n\n\n<p>3\u3001\u5b89\u88c5\u6ce8\u518c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >Vue.use(VueRouter)<\/code><\/pre>\n\n\n\n<p>4\u3001\u521b\u5efa\u8def\u7531\u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const router = new VueRouter()<\/code><\/pre>\n\n\n\n<p>5\u3001\u6ce8\u5165\uff0c\u5c06\u8def\u7531\u5bf9\u8c61\u6ce8\u5165\u5230new Vue\u5b9e\u4f8b\u4e2d\uff0c\u5efa\u7acb\u5173\u8054<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >new Vue({\r\n  render: h =&gt; h(App),\r\n  router\r\n}).$mount(&#039;#app&#039;)<\/code><\/pre>\n\n\n\n<p>2\u4e2a\u6838\u5fc3\u6b65\u9aa4<\/p>\n\n\n\n<p>1\u3001\u521b\u5efa\u9700\u8981\u7684\u7ec4\u4ef6\uff08views\u76ee\u5f55\uff09\uff0c<strong>\u914d\u7f6e\u8def\u7531\u89c4\u5219<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >import Find from &#039;.\/views\/Find.vue&#039;\r\nimport My from &#039;.\/views\/My.vue&#039;\r\nimport Friend from &#039;.\/views\/Friend.vue&#039;\r\nconst router = new VueRouter({\r\n  routes: &#091;\r\n    { path: &#039;\/find&#039;, component: Find },\r\n    { path: &#039;\/my&#039;, component: My },\r\n    { path: &#039;\/friend&#039;, component: Friend },\r\n  ]\r\n})<\/code><\/pre>\n\n\n\n<p>2\u3001\u914d\u7f6e\u5bfc\u822a\uff0c<strong>\u914d\u7f6e\u8def\u7531\u51fa\u53e3<\/strong>\uff08\u8def\u5f84\u5339\u914d\u7684\u7ec4\u4ef6\u663e\u793a\u7684\u4f4d\u7f6e\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;div class=&quot;footer_wrap&quot;&gt;\r\n  &lt;a href=&quot;#\/find&quot;&gt;\u53d1\u73b0\u97f3\u4e50&lt;\/a&gt;\r\n  &lt;a href=&quot;#\/my&quot;&gt;\u6211\u7684\u97f3\u4e50&lt;\/a&gt;\r\n  &lt;a href=&quot;#\/friend&quot;&gt;\u670b\u53cb&lt;\/a&gt;\r\n&lt;\/div&gt;\r\n&lt;div class=&quot;top&quot;&gt;\r\n  &lt;router-view&gt;&lt;\/router-view&gt;\r\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-4\">\u7ec4\u4ef6\u5b58\u653e\u76ee\u5f55\u95ee\u9898<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"641\" height=\"397\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-53.png\" alt=\"\" class=\"wp-image-890\" style=\"width:414px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-53.png 641w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-53-300x186.png 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/figure>\n\n\n\n<p>\u7ec4\u4ef6\u5b58\u653e\u76ee\u5f55\u95ee\u9898 (\u7ec4\u4ef6\u5206\u7c7b)<\/p>\n\n\n\n<p>\u7ec4\u4ef6\u5206\u7c7b\uff1a<code class=\"prettyprint\" >.vue<\/code>\u6587\u4ef6\u52062\u7c7b\uff1b <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">\u9875\u9762\u7ec4\u4ef6<\/mark><\/strong> &amp; <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u590d\u7528\u7ec4\u4ef6<\/mark><\/strong><\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u90fd\u662f <code class=\"prettyprint\" >.vue<\/code>\u6587\u4ef6 (\u672c\u8d28\u65e0\u533a\u522b)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"393\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-54-1024x393.png\" alt=\"\" class=\"wp-image-891\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-54-1024x393.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-54-300x115.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-54-768x295.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/01\/image-54.png 1218w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>\u9875\u9762\u7ec4\u4ef6<\/strong> - <code class=\"prettyprint\" >views<\/code>\u6587\u4ef6\u5939 => <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u914d\u5408\u8def\u7531\uff0c\u9875\u9762\u5c55\u793a<\/mark><\/strong><\/p>\n\n\n\n<p><strong>\u590d\u7528\u7ec4\u4ef6<\/strong> - <code class=\"prettyprint\" >components<\/code>\u6587\u4ef6\u5939 => <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u5c01\u88c5\u590d\u7528<\/mark><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5355\u9875\u5e94\u7528\u7a0b\u5e8f: SPA &#8211; Single Page Application \u5355\u9875\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e4b\u6240\u4ee5\u5f00\u53d1\u6548\u7387\u9ad8\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":888,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/886"}],"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=886"}],"version-history":[{"count":1,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/886\/revisions"}],"predecessor-version":[{"id":892,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/886\/revisions\/892"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/888"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=886"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}