admin 管理员组

文章数量: 1087139


2024年4月13日发(作者:tcpip和osi的区别)

vue3路由跳转并传值

Vue3 是一款非常流行的前端框架,其路由功能使得我们可以更方便地在

应用程序中实现单页面切换。在本篇文章中,我们将介绍 Vue3 路由的跳转方

法以及如何在不同页面之间传递数据。

一、Vue3 路由基本概念

在 Vue3 中,的路由功能是通过 `vue-router` 库实现的。首先需要安装

并引入该库:

```bash

pm install vue-router

```

然后在主应用文件中引入并配置:

```javascript

import { createApp } from "vue"

import App from "./"

import router from "./router"

createApp(App).use(router).mount("#app")

```

二、Vue3 路由跳转方法

在 Vue3 中,可以通过以下两种方式进行路由跳转:

1.使用 `()` 方法

```javascript

this.$("/new-page")

```

2.使用 `e()` 方法

```javascript

this.$e("/new-page")

```

两者都可以实现页面跳转,但 `push()` 方法会将新的路由添加到历史记录

中,而 `replace()` 方法则会覆盖原有的历史记录。


本文标签: 路由 跳转 页面 实现 文件