vue useRouter useRoute 区别及用法
·

常用使用场景:
| 点击按钮跳转页面 | useRouter().push() |
页面加载时读取 id |
useRoute().params.id |
读取 ?keyword=xxx |
useRoute().query.keyword |
| 登录后跳转回原页面 | useRouter().push({ path: '/back', query: route.query }) |
| 在非组件文件中跳转(如 axios) | window.location.href = "/login" |
总结:
router 主要用于跳转页面 router.push('/xxx')
route 主要用于获取参数/路径
更多推荐

所有评论(0)