这篇文章主要讲解了“Vue中如何动态设置路由参数”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Vue中如何动态设置路由参数”吧!
1.使用this.$router.go()
,与js histroy.go()
用法一直,前进1,后退-1,当前页面:0
注意 使用go时 必须是已经有访问历史记录了
案例:
<template>
<div>
<button @click="goht">后退<button> <br/>
<button @click="goqj">前进<button> <br/>
<button @click="gosx">刷新当前<button>
</div>
</template>
<script>
export default {
methods: {
goht(){
this.$router.go(-1);
},
goqj(){
this.$router.go(1);
},
gosx(){
this.$router.go(0); //或者 this.$router.go();
}
}
}
</script>
2.使用push调用:
案例
<template>
<div>
<button @click="pageA">去A页面</button> <br/>
<button @click="pageB">去B页面</button> <br/>
</div>
</template>
<script>
exprot default {
methods: {
pageA(){
//去路由A页面,字符串形式只能是path,类似to="path"
this.$router.push('/RouterA');
},
pageB(){
//去路由B页面,数组形式,类似 :to="{}"
this.$router.push(
{
name: 'RouterB',
query: {'name': 'name1', title: 'title1'}
//,params:{'name': 'name2', title: 'title2'}
}
);
}
}
}
</script>
感谢各位的阅读,以上就是“Vue中如何动态设置路由参数”的内容了,经过本文的学习后,相信大家对Vue中如何动态设置路由参数这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/farmerbragging/blog/4356269