• 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>

  • 相关阅读:
    sqlserver2005新特性介绍
    Sql 数据库 用户密码MD5加密
    easyui datagrid
    JQ js 对数组的操作
    c#2.0锐利体验《泛型编程》读书笔记
    jQuery EasyUI DataGrid Checkbox 数据设定与取值
    数据库的常用命令
    关于background-image设置背景图片
    Css背景设置 、
    实时监听输入框值变化的完美方案:oninput & onpropertychange
  • 原文地址:https://www.cnblogs.com/xiao-peng-ji/p/11336310.html
Copyright © 2020-2023  润新知