{"id":78,"date":"2022-05-29T14:57:07","date_gmt":"2022-05-29T06:57:07","guid":{"rendered":"http:\/\/www.33weixin.com\/index\/?p=78"},"modified":"2022-05-29T15:00:24","modified_gmt":"2022-05-29T07:00:24","slug":"%e8%b7%af%e7%94%b1","status":"publish","type":"post","link":"http:\/\/www.33weixin.com\/index\/index.php\/2022\/05\/29\/%e8%b7%af%e7%94%b1\/","title":{"rendered":"\u8def\u7531"},"content":{"rendered":"<h2 id=\"\u5b98\u65b9\u8def\u7531\">\u5b98\u65b9\u8def\u7531<\/h2>\n<p>\u5bf9\u4e8e\u5927\u591a\u6570\u5355\u9875\u9762\u5e94\u7528\uff0c\u90fd\u63a8\u8350\u4f7f\u7528\u5b98\u65b9\u652f\u6301\u7684<a href=\"https:\/\/github.com\/vuejs\/vue-router\" target=\"_blank\" rel=\"noopener\">vue-router\u5e93<\/a>\u3002\u66f4\u591a\u7ec6\u8282\u53ef\u4ee5\u770b<a href=\"http:\/\/vuejs.github.io\/vue-router\/\" target=\"_blank\" rel=\"noopener\">vue-router\u6587\u6863<\/a>\u3002<\/p>\n<h2 id=\"\u4ece\u96f6\u5f00\u59cb\u7b80\u5355\u7684\u8def\u7531\">\u4ece\u96f6\u5f00\u59cb\u7b80\u5355\u7684\u8def\u7531<\/h2>\n<p>\u5982\u679c\u53ea\u9700\u8981\u975e\u5e38\u7b80\u5355\u7684\u8def\u7531\u800c\u4e0d\u9700\u8981\u5f15\u5165\u6574\u4e2a\u8def\u7531\u5e93\uff0c\u53ef\u4ee5\u52a8\u6001\u6e32\u67d3\u4e00\u4e2a\u9875\u9762\u7ea7\u7684\u7ec4\u4ef6\u50cf\u8fd9\u6837\uff1a<\/p>\n<pre><code class=\"lang-js\"><span class=\"hljs-keyword\">const<\/span> NotFound = { template: <span class=\"hljs-string\">'&lt;p&gt;Page not found&lt;\/p&gt;'<\/span> }\n<span class=\"hljs-keyword\">const<\/span> Home = { template: <span class=\"hljs-string\">'&lt;p&gt;home page&lt;\/p&gt;'<\/span> }\n<span class=\"hljs-keyword\">const<\/span> About = { template: <span class=\"hljs-string\">'&lt;p&gt;about page&lt;\/p&gt;'<\/span> }\n\n<span class=\"hljs-keyword\">const<\/span> routes = {\n  <span class=\"hljs-string\">'\/'<\/span>: Home,\n  <span class=\"hljs-string\">'\/about'<\/span>: About\n}\n\n<span class=\"hljs-keyword\">new<\/span> Vue({\n  el: <span class=\"hljs-string\">'#app'<\/span>,\n  data: {\n    currentRoute: <span class=\"hljs-built_in\">window<\/span>.location.pathname\n  },\n  computed: {\n    ViewComponent () {\n      <span class=\"hljs-keyword\">return<\/span> routes[<span class=\"hljs-keyword\">this<\/span>.currentRoute] || NotFound\n    }\n  },\n  render (h) { <span class=\"hljs-keyword\">return<\/span> h(<span class=\"hljs-keyword\">this<\/span>.ViewComponent) }\n})\n<\/code><\/pre>\n<p>\u7ed3\u5408HTML5 History API\uff0c\u4f60\u53ef\u4ee5\u5efa\u7acb\u4e00\u4e2a\u975e\u5e38\u57fa\u672c\u4f46\u529f\u80fd\u9f50\u5168\u7684\u5ba2\u6237\u7aef\u8def\u7531\u5668\u3002\u53ef\u4ee5\u76f4\u63a5\u770b<a href=\"https:\/\/github.com\/chrisvfritz\/vue-2.0-simple-routing-example\" target=\"_blank\" rel=\"noopener\">\u5b9e\u4f8b\u5e94\u7528<\/a><\/p>\n<h2 id=\"\u6574\u5408\u7b2c\u4e09\u65b9\u8def\u7531\">\u6574\u5408\u7b2c\u4e09\u65b9\u8def\u7531<\/h2>\n<p>\u5982\u679c\u6709\u975e\u5e38\u559c\u6b22\u7684\u7b2c\u4e09\u65b9\u8def\u7531\uff0c\u5982<a href=\"https:\/\/github.com\/visionmedia\/page.js\" target=\"_blank\" rel=\"noopener\">Page.js<\/a>\u6216\u8005\u00a0<a href=\"https:\/\/github.com\/flatiron\/director\" target=\"_blank\" rel=\"noopener\">Director<\/a>, \u6574\u5408<a href=\"https:\/\/github.com\/chrisvfritz\/vue-2.0-simple-routing-example\/compare\/master...pagejs\" target=\"_blank\" rel=\"noopener\">\u5f88\u7b80\u5355<\/a>\u3002 \u8fd9\u6709\u4e2a\u7528\u4e86Page.js\u7684<a href=\"https:\/\/github.com\/chrisvfritz\/vue-2.0-simple-routing-example\/tree\/pagejs\" target=\"_blank\" rel=\"noopener\">\u590d\u6742\u793a\u4f8b<\/a>\u00a0\u3002<\/p>\n<hr \/>\n<blockquote><p>\u539f\u6587\uff1a\u00a0<a href=\"http:\/\/vuejs.org\/guide\/routing.html\" target=\"_blank\" rel=\"noopener\">http:\/\/vuejs.org\/guide\/routing.html<\/a><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u65b9\u8def\u7531 \u5bf9\u4e8e\u5927\u591a\u6570\u5355\u9875\u9762\u5e94\u7528\uff0c\u90fd\u63a8\u8350\u4f7f\u7528\u5b98\u65b9\u652f\u6301\u7684vue-router\u5e93\u3002\u66f4\u591a\u7ec6\u8282\u53ef\u4ee5\u770bvue-router&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/78"}],"collection":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/comments?post=78"}],"version-history":[{"count":1,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":79,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/78\/revisions\/79"}],"wp:attachment":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/media?parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/categories?post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/tags?post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}