gpt4 book ai didi

Vue.js 重定向到另一个页面

转载 作者:搜寻专家 更新时间:2023-10-30 22:07:15 24 4
gpt4 key购买 nike

我想在 Vue.js 中做一个类似于 vanilla javascript 的重定向

window.location.href = 'some_url'

我如何在 Vue.js 中实现这一点?

最佳答案

如果你正在使用 vue-router,你应该使用 router.go(path) 来导航到任何特定的路线。可以使用 this.$router 从组件内访问路由器。

否则,window.location.href = 'some url'; 适用于非单页应用。

编辑:router.go() 在 VueJS 2.0 中发生了变化。您现在可以使用 $router.push({ name: "yourroutename"}) 或仅使用 router.push("yourroutename") 进行重定向。

Documentation

注意:在 Controller 中使用:this.$router.push({ name: 'routename' })

关于Vue.js 重定向到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35664550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com