在 Vue.js 中,有以下三种打开新页面的方法:1. 使用 组件;2. 使用 $router.push() 方法;3. 使用 window.location.href 属性。
Vue 中打开新页面的方法
在 Vue.js 中,有以下几种打开新页面的方法:
1. 使用
立即学习“前端免费学习笔记(深入)”;
示例:
<template> <router-link to="/new-page">Open New Page</router-link> </template> <script> import { defineComponent } from 'vue'; import { useRouter } from 'vue-router'; export default defineComponent({ setup() { const router = useRouter(); return { router, }; }, }); </script>
2. 使用 $router.push() 方法
$router.push() 方法用于编程方式导航到一个新的页面。它将一个新的路由条目推送到路由堆栈中,从而打开新的页面。
示例:
this.$router.push('/new-page');
3. 使用 window.location.href
window.location.href 属性可以用来设置或获取当前页面的 URL。通过直接修改此属性,可以打开一个新的页面。
示例:
window.location.href = '/new-page';
以上就是vue怎么打开新页面的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号