在 Vue.js 中,可以通过 组件或 router.push() 方法跳转页面。 组件用于创建可点击链接,而 router.push() 方法用于以编程方式跳转。此外,可以传递参数、使用 named route,以及使用 replace: true 替换历史记录。
Vue.js 页面跳转指南
如何使用 Vue.js 跳转到新页面?
在 Vue.js 中,可以通过
使用
立即学习“前端免费学习笔记(深入)”;
<template> <router-link to="/about">关于我们</router-link> </template>
使用 router.push() 方法
router.push() 方法用于以编程方式进行页面跳转。它接受一个路径或路由对象作为参数,并触发页面跳转。
this.$router.push('/about')
详细说明
使用 named route
可以使用 named route 来跳转到特定路由,例如:
<router-link :to="{ name: 'about' }">关于</router-link>
this.$router.push({ name: 'about' })
传递参数
可以使用 params 或 query 属性传递参数到新页面:
<router-link :to="{ path: '/user', params: { id: 123 } }">用户详情</router-link>
this.$router.push({ path: '/user', query: { id: 123 } })
使用 replace: true
如果希望替换历史记录中当前页面,可以使用 replace: true 选项:
this.$router.push({ path: '/about', replace: true })
以上就是vue怎么跳转新的页面的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号