Vue.js提供了三种跳转方式:原生 JavaScript API:使用 window.location.href 进行跳转。Vue Router:使用 标签或 this.$router.push() 方法进行跳转。VueX:通过 dispatch action 或 commit mutation 来触发路由跳转。
使用原生 JavaScript API 跳转页面:
window.location.href = 'new-page.html';
Vue Router 是 Vue.js 的官方路由库,提供了更完善的路由管理功能:
<router-link to="/new-page">跳转到新页面</router-link>
this.$router.push() 方法:在当前路由栈中添加新路由。
立即学习“前端免费学习笔记(深入)”;
this.$router.push('/new-page');
this.$router.replace() 方法:替换当前路由,不会出现在历史记录中。
this.$router.replace('/new-page');
VueX 是 Vue.js 的状态管理库,可以用它来触发路由跳转:
Action:提交一个 action 来触发路由跳转。
store.dispatch('changeRoute', '/new-page');
Mutation:在 mutation 中调用 $router.push() 或 $router.replace() 方法。
store.commit('changeRoute', { path: '/new-page' });
选择哪种跳转方式取决于具体需求:
以上就是vue引入方式怎么跳转的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号