zoukankan      html  css  js  c++  java
  • Vue 页面跳转

    Vue 页面跳转的 5 种方式

    this.$router.push
    this.$router.replace
    this.$router.go
    this.$router.back
    this.$router.forward
    

    this.$router.push

    想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。

    示例:

    // 保留当前页,页面跳转至 /home 页
    this.$router.replace("/home");
    

    this.$router.replace

    跟 router.push 很像,唯一的不同就是,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录。

    示例:

    // 取代当前页,页面跳转至 /home 页
    this.$router.replace("/home");
    

    this.$router.go

    这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步。参数为 0 时会重新加载页面,但会有短暂白屏。

    // 回退两个页面
    this.$router.go(-2);
    

    this.$router.back

    在 history 记录中,返回上一页。

    this.$router.forward

    在 history 记录中,前往下一页。

    参考资源

    vue-router 官方文档

    https://blog.csdn.net/fufu_dclt/article/details/105134806

    每天学习一点点,每天进步一点点。

  • 相关阅读:
    Django 框架
    Git 教程
    Vue详解
    pycharm激活码
    通过元类创建一个Python类
    re模块
    selenium模块
    Beautifulsoup模块基础详解
    requests库
    Urllib库
  • 原文地址:https://www.cnblogs.com/youcoding/p/14563649.html
Copyright © 2011-2022 走看看