当前位置:Gxlcms > JavaScript > 关于Vue动态设置路由参数的介绍

关于Vue动态设置路由参数的介绍

时间:2021-07-01 10:21:17 帮助过:13人阅读

这篇文章主要介绍了Vue 动态设置路由参数的案例分析,非常不错,具有参考借鉴价值,需要的朋友可以参考下

在vue中 可以动态设置路由参数:

1.使用this.$router.go(),与js histroy.go() 用法一直,前进1,后退-1,当前页面:0

注意 使用go时 必须是已经有访问历史记录了

案例:

  1. <template>
  2. <p>
  3. <button @click="goht">后退<button> <br/>
  4. <button @click="goqj">前进<button> <br/>
  5. <button @click="gosx">刷新当前<button>
  6. </p>
  7. </template>
  8. <script>
  9. export default {
  10. methods: {
  11. goht(){
  12. this.$router.go(-1);
  13. },
  14. goqj(){
  15. this.$router.go(1);
  16. },
  17. gosx(){
  18. this.$router.go(0); //或者 this.$router.go();
  19. }
  20. }
  21. }
  22. </script>

2.使用push调用:

案例

  1. <template>
  2. <p>
  3. <button @click="pageA">去A页面</button> <br/>
  4. <button @click="pageB">去B页面</button> <br/>
  5. </p>
  6. </template>
  7. <script>
  8. exprot default {
  9. methods: {
  10. pageA(){
  11. //去路由A页面,字符串形式只能是path,类似to="path"
  12. this.$router.push('/RouterA');
  13. },
  14. pageB(){
  15. //去路由B页面,数组形式,类似 :to="{}"
  16. this.$router.push(
  17. {
  18. name: 'RouterB',
  19. query: {'name': 'name1', title: 'title1'}
  20. //,params:{'name': 'name2', title: 'title2'}
  21. }
  22. );
  23. }
  24. }
  25. }
  26. </script>

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

使用vuex的state状态对象的方式

基于vue cli重构多页面脚手架过程的介绍

以上就是关于Vue 动态设置路由参数的介绍的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行