{"id":236608,"date":"2022-03-07T09:17:44","date_gmt":"2022-03-07T01:17:44","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=236608"},"modified":"2022-02-24T21:18:34","modified_gmt":"2022-02-24T13:18:34","slug":"vue-route-jump","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/vue-route-jump.html","title":{"rendered":"\u8be6\u89e3vue \u8def\u7531\u8df3\u8f6c\u56db\u79cd\u65b9\u5f0f (\u5e26\u53c2\u6570)"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6587\u4ecb\u7ecd\u4e86vue \u8def\u7531\u8df3\u8f6c\u56db\u79cd\u65b9\u5f0f (\u5e26\u53c2\u6570)\uff0c\u672c\u6587\u901a\u8fc7\u5b9e\u4f8b\u4ee3\u7801\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u8be6\u7ec6\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u501f\u9274\u4ef7\u503c,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

1. router-link<\/strong><\/div>\n
1. \u4e0d\u5e26\u53c2\u6570<\/strong><\/span><\/div>\n
\r\n <router-link :to="{name:'home'}"> \r\n<router-link :to="{path:'\/home'}"> \/\/name,path\u90fd\u884c, \u5efa\u8bae\u7528name \r\n\/\/ \u6ce8\u610f\uff1arouter-link\u4e2d\u94fe\u63a5\u5982\u679c\u662f'\/'\u5f00\u59cb\u5c31\u662f\u4ece\u6839\u8def\u7531\u5f00\u59cb\uff0c\u5982\u679c\u5f00\u59cb\u4e0d\u5e26'\/'\uff0c\u5219\u4ece\u5f53\u524d\u8def\u7531\u5f00\u59cb\u3002\r\n<\/pre>\n
2.\u5e26\u53c2\u6570<\/strong><\/span><\/div>\n
\r\n<router-link :to="{name:'home', params: {id:1}}"> \r\n\/\/ params\u4f20\u53c2\u6570 (\u7c7b\u4f3cpost)\r\n\/\/ \u8def\u7531\u914d\u7f6e path: "\/home\/:id" \u6216\u8005 path: "\/home:id" \r\n\/\/ \u4e0d\u914d\u7f6epath ,\u7b2c\u4e00\u6b21\u53ef\u8bf7\u6c42,\u5237\u65b0\u9875\u9762id\u4f1a\u6d88\u5931\r\n\/\/ \u914d\u7f6epath,\u5237\u65b0\u9875\u9762id\u4f1a\u4fdd\u7559\r\n\/\/ html \u53d6\u53c2 $route.params.id\r\n\/\/ script \u53d6\u53c2 this.$route.params.id\r\n<router-link :to="{name:'home', query: {id:1}}"> \r\n\/\/ query\u4f20\u53c2\u6570 (\u7c7b\u4f3cget,url\u540e\u9762\u4f1a\u663e\u793a\u53c2\u6570)\r\n\/\/ \u8def\u7531\u53ef\u4e0d\u914d\u7f6e\r\n\/\/ html \u53d6\u53c2 $route.query.id\r\n\/\/ script \u53d6\u53c2 this.$route.query.id\r\n<\/pre>\n
2. this.$router.push() (\u51fd\u6570\u91cc\u9762\u8c03\u7528)<\/strong><\/div>\n
1. \u4e0d\u5e26\u53c2\u6570<\/strong><\/span><\/div>\n
\r\nthis.$router.push('\/home')\r\nthis.$router.push({name:'home'})\r\nthis.$router.push({path:'\/home'})\r\n<\/pre>\n
2. query\u4f20\u53c2<\/strong><\/span><\/div>\n
\r\n this.$router.push({name:'home',query: {id:'1'}})\r\nthis.$router.push({path:'\/home',query: {id:'1'}})\r\n\/\/ html \u53d6\u53c2 $route.query.id\r\n\/\/ script \u53d6\u53c2 this.$route.query.id\r\n<\/pre>\n
3. params\u4f20\u53c2<\/strong><\/span><\/div>\n
\r\n this.$router.push({name:'home',params: {id:'1'}}) \/\/ \u53ea\u80fd\u7528 name\r\n  \r\n\/\/ \u8def\u7531\u914d\u7f6e path: \"\/home\/:id\" \u6216\u8005 path: \"\/home:id\" ,\r\n\/\/ \u4e0d\u914d\u7f6epath ,\u7b2c\u4e00\u6b21\u53ef\u8bf7\u6c42,\u5237\u65b0\u9875\u9762id\u4f1a\u6d88\u5931\r\n\/\/ \u914d\u7f6epath,\u5237\u65b0\u9875\u9762id\u4f1a\u4fdd\u7559\r\n\/\/ html \u53d6\u53c2 $route.params.id\r\n\/\/ script \u53d6\u53c2 this.$route.params.id\r\n<\/pre>\n
4. query\u548cparams\u533a\u522b<\/strong><\/span><\/div>\n

query\u7c7b\u4f3c get, \u8df3\u8f6c\u4e4b\u540e\u9875\u9762 url\u540e\u9762\u4f1a\u62fc\u63a5\u53c2\u6570,\u7c7b\u4f3c?id=1, \u975e\u91cd\u8981\u6027\u7684\u53ef\u4ee5\u8fd9\u6837\u4f20, \u5bc6\u7801\u4e4b\u7c7b\u8fd8\u662f\u7528params\u5237\u65b0\u9875\u9762id\u8fd8\u5728
\nparams\u7c7b\u4f3c post, \u8df3\u8f6c\u4e4b\u540e\u9875\u9762 url\u540e\u9762\u4e0d\u4f1a\u62fc\u63a5\u53c2\u6570 , \u4f46\u662f\u5237\u65b0\u9875\u9762id \u4f1a\u6d88\u5931\u3002<\/p>\n

3. this.$router.replace() <\/strong><\/span><\/div>\n

(\u7528\u6cd5\u540c\u4e0a,push)<\/p>\n

4. this.$router.go(n) ()<\/strong><\/span><\/div>\n
\r\nthis.$router.go(n)\r\n<\/pre>\n

\u5411\u524d\u6216\u8005\u5411\u540e\u8df3\u8f6cn\u4e2a\u9875\u9762\uff0cn\u53ef\u4e3a\u6b63\u6574\u6570\u6216\u8d1f\u6574\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

<router-link :to="{name:'home'}" […]<\/p>\n","protected":false},"author":1903,"featured_media":236629,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-236608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=236608"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236608\/revisions"}],"predecessor-version":[{"id":236633,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236608\/revisions\/236633"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/236629"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=236608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=236608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=236608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}