在 Vue 中,可以使用 <router-link> 组件或 this.$router.push() 方法进行页面跳转。

  1. 使用 <router-link> 组件: 在模板中使用 <router-link> 组件来创建页面链接,它会自动渲染成 <a> 标签,并且会自动添加活动类(active class):

    <router-link to="/path">跳转到目标页面</router-link>
    
  2. 使用 this.$router.push() 方法: 在组件的 JavaScript 代码中,可以使用 this.$router.push() 方法来进行页面跳转。该方法接收一个路由对象或一个路径字符串作为参数:

    // 跳转到目标页面(通过路径字符串)
    this.$router.push('/path');
    
    // 跳转到目标页面(通过路由对象)
    this.$router.push({ path: '/path' });
    

    另外,还可以使用命名路由、带参数的路由等方式进行页面跳转,具体可以参考 Vue Router 的官方文档:https://router.vuejs.org/zh/api/#router-pus

vue怎样跳转页面

原文地址: http://www.cveoy.top/t/topic/hRmp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录