zoukankan      html  css  js  c++  java
  • vuerouter-4.编程式导航

    1.router.push

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

    2.router.replace

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

    3.router.go()

    这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n)

    实例---------------------------------------------------------------------------

    <template>
    <div id="app">
    <img src="./assets/logo.png">
    <ul>
    <router-link to="/h" tag="li">HelloWorld</router-link>
    <router-link to="/learn" tag="li">learn</router-link>
    </ul>
    <button class="btn" @click="gotoHello">去HelloWorld</button>
    <router-view />
    </div>
    </template>

    <script>
    export default {
    name: 'App',
    components: {

    },
    methods: {
    gotoHello() {
    //this.$router.push("/h")
    //this.$router.replace("/h")
    this.$router.go(-1)
    }
    }
    }
    </script>

    <style>
    #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
    }

    ul li {
    text-align: center;
    display: inline-block;
    text-decoration: underline;
    cursor: pointer;
    color: blue;
    }

    ul li+li {
    margin-left: 20px;
    }

    .btn {
    border: 1px solid #fff;
    padding: 5px;
    color: #fff;
    background-color: #0000FF;
    cursor: pointer;
    }
    </style>

  • 相关阅读:
    linux 常用命令(个人记录)
    jmeter 5.0版本更新说明(个人做个记录)
    Netdata---Linux系统性能实时监控平台部署记录
    MySQL Yum存储库 安装、升级、集群
    linux 各项配置汇总
    构建Maven项目自动下载jar包
    计算服务器的pv量算法
    性能计算公式
    jstack(查看线程)、jmap(查看内存)和jstat(性能分析)命令
    结构模式
  • 原文地址:https://www.cnblogs.com/xiao-peng-ji/p/11336310.html
Copyright © 2011-2022 走看看