码迷,mamicode.com
首页 > 其他好文 > 详细

vuerouter-4.编程式导航

时间:2019-08-11 20:25:32      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:button   记录   就是   set   bsp   back   mda   log   push   

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>

vuerouter-4.编程式导航

标签:button   记录   就是   set   bsp   back   mda   log   push   

原文地址:https://www.cnblogs.com/xiao-peng-ji/p/11336310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!