当前位置:首页 > VUE

vue文件实现页面跳转

2026-01-12 04:59:06VUE

使用 router-link 实现跳转

在 Vue 模板中直接使用 <router-link> 组件,通过 to 属性指定目标路径:

<router-link to="/target-page">跳转到目标页</router-link>

动态路径可通过 :to 绑定对象实现:

<router-link :to="{ path: '/target-page' }">路径跳转</router-link>
<router-link :to="{ name: 'TargetPage' }">命名路由跳转</router-link>

编程式导航

通过 this.$router.push() 方法在脚本中跳转:

// 路径跳转
this.$router.push('/target-page');
// 对象形式跳转
this.$router.push({ path: '/target-page' });
// 命名路由跳转
this.$router.push({ name: 'TargetPage' });
// 带参数跳转
this.$router.push({ path: '/target-page', query: { id: 123 } });

路由传参

通过 paramsquery 传递参数:

// params 传参(需路由配置占位)
this.$router.push({ name: 'TargetPage', params: { id: 123 } });
// query 传参(URL显示参数)
this.$router.push({ path: '/target-page', query: { id: 123 } });

目标页面通过 this.$route.paramsthis.$route.query 接收参数。

路由配置示例

确保路由已配置目标页面:

const routes = [
  {
    path: '/target-page',
    name: 'TargetPage',
    component: () => import('./views/TargetPage.vue')
  }
];

替换当前路由

使用 this.$router.replace() 替换当前历史记录:

this.$router.replace({ path: '/target-page' });

返回上一页

通过 this.$router.go(-1) 返回:

this.$router.go(-1);

动态路由匹配

路由配置中使用动态字段:

{
  path: '/target-page/:id',
  component: () => import('./views/TargetPage.vue')
}

跳转时传递参数:

vue文件实现页面跳转

this.$router.push('/target-page/123');

标签: 跳转页面
分享给朋友:

相关文章

js实现跳转

js实现跳转

使用 window.location 跳转 通过修改 window.location.href 或直接使用 window.location 实现页面跳转,适用于普通跳转或带参数的 URL。 // 方…

vue实现反馈页面

vue实现反馈页面

Vue 实现反馈页面的方法 基础表单结构 使用 Vue 的模板语法构建反馈表单,包含输入框、下拉选择、复选框等基础元素。表单需绑定 v-model 实现数据双向绑定。 <template>…

vue实现页面刻度

vue实现页面刻度

实现页面刻度的基本思路 在Vue中实现页面刻度通常用于展示进度、测量或标记特定位置。可以通过动态计算和渲染刻度元素来实现,结合CSS样式控制显示效果。 使用动态渲染刻度线 通过v-for指令动态生成…

vue 实现页面跳转

vue 实现页面跳转

Vue 实现页面跳转的方法 在 Vue 中实现页面跳转可以通过多种方式,主要包括使用 Vue Router 提供的导航方法和原生 JavaScript 的方式。 使用 Vue Router 的 ro…

vue页面布局实现

vue页面布局实现

Vue 页面布局实现方法 基础布局结构 使用 Vue 单文件组件(SFC)构建页面框架,结合 <template>、<script> 和 <style> 三个部分。…

uniapp结算页面

uniapp结算页面

uniapp 结算页面实现 页面布局设计 结算页面通常包含商品列表、价格汇总、收货地址和支付方式选择。使用 uni-list 组件展示商品信息,uni-forms 收集用户收货信息,radio-gro…