{"id":164465,"date":"2024-05-08T14:55:07","date_gmt":"2024-05-08T06:55:07","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/164465.html"},"modified":"2024-05-08T14:55:10","modified_gmt":"2024-05-08T06:55:10","slug":"vue3-%e5%bc%80%e5%8f%91%e5%b8%b8%e8%a7%81%e7%9a%84%e8%b7%af%e7%94%b1%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/164465.html","title":{"rendered":"vue3 \u5f00\u53d1\u5e38\u89c1\u7684\u8def\u7531\u6709\u54ea\u4e9b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26231314\/4d73eb89-ef34-4fac-93a2-89370fbec85a.webp\" alt=\"vue3 \u5f00\u53d1\u5e38\u89c1\u7684\u8def\u7531\u6709\u54ea\u4e9b\" \/><\/p>\n<p><p>\u5728Vue3\u5f00\u53d1\u4e2d\uff0c\u5e38\u89c1\u7684\u8def\u7531\u5305\u62ec<strong>\u9759\u6001\u8def\u7531\u3001\u52a8\u6001\u8def\u7531\u3001\u5d4c\u5957\u8def\u7531\u3001\u7f16\u7a0b\u5f0f\u8def\u7531\u3001\u547d\u540d\u8def\u7531\u3001\u8def\u7531\u5b88\u536b<\/strong>\uff0c\u5176\u4e2d\u52a8\u6001\u8def\u7531\u5728\u5b9e\u9645\u7684\u5f00\u53d1\u5de5\u4f5c\u4e2d\u5c24\u4e3a\u91cd\u8981\u3002<strong>\u52a8\u6001\u8def\u7531<\/strong>\u662f\u6307\u90a3\u4e9b\u8def\u5f84\u4e2d\u5305\u542b\u52a8\u6001\u7247\u6bb5\u7684\u8def\u7531\uff0c\u5b83\u53ef\u4ee5\u5339\u914d\u4e0d\u540c\u8def\u5f84\u7684\u540c\u4e00\u6a21\u5f0f\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u4ee5\u7528\u6237ID\u4e3a\u53c2\u6570\u7684\u7528\u6237\u9875\u9762\u8def\u5f84\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3a&#039;\/user\/:id&#039;\uff0c\u5176\u4e2d:id\u662f\u4e00\u4e2a\u52a8\u6001\u7247\u6bb5\uff0c\u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u7528\u6237\u7684ID\uff0c\u8fd9\u6837\u5728\u9875\u9762\u8df3\u8f6c\u65f6\uff0c\u5c31\u53ef\u4ee5\u590d\u7528\u540c\u4e00\u4e2a\u7ec4\u4ef6\u6765\u663e\u793a\u4e0d\u540c\u7528\u6237\u7684\u4e2a\u4eba\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u9759\u6001\u8def\u7531<\/h3>\n<\/p>\n<p><p><strong>\u9759\u6001\u8def\u7531<\/strong>\u662f\u6700\u57fa\u672c\u7684\u8def\u7531\u5f62\u5f0f\u3002\u5b83\u4eec\u7684\u8def\u5f84\u662f\u4e0d\u53d8\u7684\uff0c\u610f\u5473\u7740\u6bcf\u4e00\u4e2a\u8def\u7531\u5730\u5740\u5bf9\u5e94\u4e00\u4e2a\u5355\u4e00\u7684\u7ec4\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\u914d\u7f6e\u9759\u6001\u8def\u7531\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u58f0\u660e\u6bcf\u4e00\u4e2a\u8def\u7531\u5bf9\u8c61\u548c\u5b83\u5bf9\u5e94\u7684\u7ec4\u4ef6\u5373\u53ef\u3002<\/li>\n<li>\u9759\u6001\u8def\u7531\u901a\u5e38\u7528\u4e8e\u5e94\u7528\u7684\u4e3b\u8981\u533a\u5757\uff0c\u5982\u9996\u9875\u3001\u5173\u4e8e\u9875\u9762\u6216\u8054\u7cfb\u65b9\u5f0f\u9875\u9762\u3002<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u52a8\u6001\u8def\u7531<\/h3>\n<\/p>\n<p><p><strong>\u52a8\u6001\u8def\u7531<\/strong>\u662f\u66f4\u4e3a\u7075\u6d3b\u7684\u4e00\u79cd\u8def\u7531\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u8ba9\u4f60\u5b9a\u4e49\u53ef\u53d8\u7684\u8def\u5f84\u3002\u5f53\u4f60\u9700\u8981\u6839\u636e\u76f8\u540c\u7684\u6a21\u5f0f\u5c55\u793a\u4e0d\u540c\u5185\u5bb9\u65f6\uff0c\u5b83\u4eec\u5c24\u5176\u6709\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li>\u52a8\u6001\u8def\u7531\u901a\u8fc7\u4f7f\u7528\u5192\u53f7(:)\u6765\u6807\u8bb0\u8def\u5f84\u4e2d\u7684\u53d8\u91cf\u90e8\u5206\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u8def\u5f84\u6a21\u5f0f&#039;\/users\/:userId&#039;, \u5176\u4e2duserId\u662f\u4e00\u4e2a\u52a8\u6001\u6bb5\u843d\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u7684\u7528\u6237ID\u6539\u53d8\u3002<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u5d4c\u5957\u8def\u7531<\/h3>\n<\/p>\n<p><p><strong>\u5d4c\u5957\u8def\u7531<\/strong>\u5141\u8bb8\u4f60\u521b\u5efa\u4e00\u4e2a\u7531\u591a\u5c42\u7ec4\u4ef6\u7ec4\u6210\u7684\u8def\u7531\u7ed3\u6784\uff0c\u8fd9\u5bf9\u4e8e\u6784\u5efa\u5177\u6709\u591a\u5c42\u6b21\u7684\u7528\u6237\u754c\u9762\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li>\u8981\u914d\u7f6e\u5d4c\u5957\u8def\u7531\uff0c\u4f60\u9700\u8981\u5728\u7236\u8def\u7531\u5bf9\u8c61\u7684children\u6570\u7ec4\u4e2d\u5b9a\u4e49\u5b50\u8def\u7531\u3002<\/li>\n<li>\u5d4c\u5957\u8def\u7531\u80fd\u591f\u8ba9\u4f60\u5c06\u5e94\u7528\u5206\u5272\u6210\u66f4\u5c0f\u7684\u90e8\u5206\uff0c\u4f7f\u5176\u66f4\u5bb9\u6613\u7ba1\u7406\u4e0e\u7ef4\u62a4\u3002<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u7f16\u7a0b\u5f0f\u8def\u7531<\/h3>\n<\/p>\n<p><p><strong>\u7f16\u7a0b\u5f0f\u8def\u7531<\/strong>\u6307\u7684\u662f\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee3\u7801\u6765\u5b9e\u73b0\u9875\u9762\u7684\u8df3\u8f6c\uff0c\u800c\u4e0d\u662f\u7528\u6237\u70b9\u51fb\u94fe\u63a5\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<ol>\n<li>Vue Router\u63d0\u4f9b\u4e86push\u548creplace\u65b9\u6cd5\u6765\u5b9e\u73b0\u7f16\u7a0b\u5f0f\u7684\u5bfc\u822a\u3002<\/li>\n<li>\u4f7f\u7528\u7f16\u7a0b\u5f0f\u8def\u7531\u53ef\u4ee5\u8ba9\u4f60\u6709\u66f4\u591a\u63a7\u5236\u6743\uff0c\u5bf9\u4e8e\u5904\u7406\u590d\u6742\u7684\u5bfc\u822a\u903b\u8f91\u5c24\u5176\u6709\u7528\u3002<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u547d\u540d\u8def\u7531<\/h3>\n<\/p>\n<p><p><strong>\u547d\u540d\u8def\u7531<\/strong>\u53ef\u4ee5\u8ba9\u4f60\u4e3a\u8def\u7531\u914d\u7f6e\u4e00\u4e2a\u552f\u4e00\u7684\u540d\u5b57\uff0c\u8fd9\u8ba9\u94fe\u63a5\u7684\u6784\u5efa\u66f4\u52a0\u6e05\u6670\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5f53\u94fe\u63a5\u5230\u4e00\u4e2a\u547d\u540d\u8def\u7531\u65f6\uff0c\u4f60\u53ef\u4ee5\u53ea\u901a\u8fc7\u540d\u5b57\u6765\u6307\u5b9a\u76ee\u6807\u8def\u7531\uff0c\u800c\u4e0d\u662f\u5199\u51fa\u5b8c\u6574\u7684URL\u3002<\/li>\n<li>\u8fd9\u5bf9\u4e8e\u7ef4\u62a4\u5927\u578b\u5e94\u7528\u975e\u5e38\u6709\u5229\uff0c\u56e0\u4e3a\u5b83\u4f7f\u5f97\u8def\u7531\u7684\u4fee\u6539\u53d8\u5f97\u66f4\u7b80\u5355\u3002<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u8def\u7531\u5b88\u536b<\/h3>\n<\/p>\n<p><p><strong>\u8def\u7531\u5b88\u536b<\/strong>\u662fVue Router\u63d0\u4f9b\u7684\u4e00\u79cd\u529f\u80fd\uff0c\u7528\u4e8e\u63a7\u5236\u8bbf\u95ee\u6743\u9650\u548c\u7ba1\u7406\u5bfc\u822a\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5f00\u53d1\u8005\u53ef\u4ee5\u5229\u7528\u8def\u7531\u5b88\u536b\u5728\u8def\u7531\u53d1\u751f\u5b9e\u9645\u53d8\u5316\u4e4b\u524d\u548c\u4e4b\u540e\u6267\u884c\u4ee3\u7801\uff0c\u4f8b\u5982\u9a8c\u8bc1\u7528\u6237\u662f\u5426\u767b\u5f55\u3002<\/li>\n<li>\u8def\u7531\u5b88\u536b\u6709\u5168\u5c40\u5b88\u536b\u3001\u8def\u7531\u72ec\u4eab\u5b88\u536b\u548c\u7ec4\u4ef6\u5185\u5b88\u536b\u7b49\u3002<\/li>\n<\/ol>\n<p><p>\u5728Vue3\u5e94\u7528\u4e2d\uff0c\u8fd9\u4e9b\u8def\u7531\u5404\u6709\u5176\u7528\u9014\u548c\u573a\u666f\uff0c\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u548c\u7ec4\u5408\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5e94\u7528\u7684\u7528\u6237\u4f53\u9a8c\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. vue3\u4e2d\u5e38\u7528\u7684\u8def\u7531\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\n\u5728vue3\u5f00\u53d1\u4e2d\uff0c\u5e38\u7528\u7684\u8def\u7531\u6709Vue Router\u548cVue Navigation\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u5728vue3\u4e2d\u4f7f\u7528Vue Router\u8fdb\u884c\u8def\u7531\u7ba1\u7406\uff1f<\/strong><br \/>\n\u5728vue3\u4e2d\u4f7f\u7528Vue Router\u8fdb\u884c\u8def\u7531\u7ba1\u7406\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u9700\u8981\u5728\u9879\u76ee\u4e2d\u5b89\u88c5Vue Router\u4f9d\u8d56\u5e76\u5bfc\u5165Vue Router\u3002\u7136\u540e\uff0c\u521b\u5efa\u4e00\u4e2a\u8def\u7531\u5b9e\u4f8b\uff0c\u914d\u7f6e\u8def\u7531\u89c4\u5219\u548c\u5bf9\u5e94\u7684\u7ec4\u4ef6\u3002\u6700\u540e\uff0c\u5c06\u8def\u7531\u5b9e\u4f8b\u6302\u8f7d\u5230Vue\u5e94\u7528\u4e2d\uff0c\u5373\u53ef\u5b9e\u73b0\u8def\u7531\u7684\u529f\u80fd\u3002<\/p>\n<p><strong>3. vue3\u4e2d\u6709\u6ca1\u6709\u5176\u4ed6\u66ff\u4ee3Vue Router\u7684\u8def\u7531\u7ba1\u7406\u65b9\u6848\uff1f<\/strong><br \/>\n\u9664\u4e86Vue Router\uff0cvue3\u8fd8\u5f15\u5165\u4e86\u4e00\u4e2a\u65b0\u7684\u8def\u7531\u7ba1\u7406\u65b9\u6848\u2014\u2014Vue Navigation\u3002Vue Navigation\u63d0\u4f9b\u4e86\u66f4\u7075\u6d3b\u7684\u8def\u7531\u7ba1\u7406\u65b9\u5f0f\uff0c\u5e76\u4e14\u652f\u6301\u52a8\u6001\u8def\u7531\u3001\u8def\u7531\u5b88\u536b\u4ee5\u53ca\u8def\u7531\u72b6\u6001\u7ba1\u7406\u7b49\u529f\u80fd\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u9002\u5408\u81ea\u5df1\u9879\u76ee\u7684\u8def\u7531\u7ba1\u7406\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Vue3\u5f00\u53d1\u4e2d\uff0c\u5e38\u89c1\u7684\u8def\u7531\u5305\u62ec\u9759\u6001\u8def\u7531\u3001\u52a8\u6001\u8def\u7531\u3001\u5d4c\u5957\u8def\u7531\u3001\u7f16\u7a0b\u5f0f\u8def\u7531\u3001\u547d\u540d\u8def\u7531\u3001\u8def\u7531\u5b88\u536b\uff0c\u5176\u4e2d\u52a8\u6001\u8def\u7531\u5728\u5b9e [&hellip;]","protected":false},"author":3,"featured_media":164468,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/164465"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=164465"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/164465\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/164468"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=164465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=164465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=164465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}