vue3如何跳转路由
时间: 2023-09-13 13:07:14 浏览: 121
在Vue 3中,可以使用`useRouter`来进行路由的跳转。首先,需要从vue-router中引入`useRouter`。然后,在`<script setup>`块中将`router`对象初始化为`useRouter()`的返回值。接下来,可以使用`router.push()`方法来进行路由跳转。例如,可以通过指定路径进行跳转,如`router.push('/login')`。此外,也可以根据路由的名称进行跳转。具体的代码可以参考下面的示例:
```vue
<script setup>
import { useRouter } from "vue-router";
const router = useRouter()
const go = () => {
router.push('/login')
}
</script>
<template>
<button @click="go">跳转</button>
</template>
```
在这个示例中,通过点击按钮触发`go`方法,然后调用`router.push('/login')`来进行路由跳转。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [vue3路由跳转方法](https://blog.csdn.net/jdhrucn/article/details/126945946)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [vue3的路由跳转](https://blog.csdn.net/LoveDcolor/article/details/130850157)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文