App.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div id="app">
  3. <nav>
  4. <router-link to="/">Home</router-link> |
  5. <router-link to="/about">About</router-link>|
  6. <!-- router-link to属性是填写页面跳转path -->
  7. <router-link to="/mypage">MyPage</router-link>|
  8. <!-- 实现路由重定向 -->
  9. <router-link to="/backhome">返回首页</router-link>|
  10. <router-link to="/mypage/childthree/王五/21">重定向子路由三</router-link
  11. >|
  12. <!-- 别名 -->
  13. <router-link to="/my">我的页面</router-link>
  14. <button @click="goPage">编程式导航</button>
  15. <router-link to="/testcomp">组件测试</router-link>|
  16. <router-link to="/lovecoding">lovecoding</router-link>|
  17. <router-link to="/addcomp">累加器</router-link>
  18. </nav>
  19. <!-- router-view 用来展示切换页面的地方 -->
  20. <div class="content">
  21. <transition name="fade">
  22. <router-view />
  23. </transition>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. methods: {
  30. goPage() {
  31. // $router.push 用来实现页面跳转 参数部分使用的是 router-link to属性的参数
  32. // this.$router.push("/about");
  33. // $router.go 用来实现页面前进后退 参数为正数表示前进 负数后退
  34. this.$router.go(-1);
  35. },
  36. },
  37. };
  38. </script>
  39. <style>
  40. .content{
  41. position: relative;
  42. width: 100vw;
  43. }
  44. .fade-enter {
  45. transform: translateX(100%);
  46. }
  47. .fade-enter-active {
  48. transition: all 0.5s;
  49. position: absolute;
  50. top: 0;
  51. width: 100vw;
  52. }
  53. .fade-enter-to {
  54. transform: translateX(0);
  55. }
  56. .fade-leave {
  57. transform: translateX(0);
  58. }
  59. .fade-leave-active {
  60. transition: all 0.5s;
  61. position: absolute;
  62. top: 0;
  63. width: 100vw;
  64. }
  65. .fade-leave-to {
  66. transform: translateX(-100%);
  67. }
  68. #app {
  69. font-family: Avenir, Helvetica, Arial, sans-serif;
  70. -webkit-font-smoothing: antialiased;
  71. -moz-osx-font-smoothing: grayscale;
  72. text-align: center;
  73. color: #2c3e50;
  74. width: 100vw;
  75. position: relative;
  76. }
  77. nav {
  78. padding: 30px;
  79. }
  80. nav a {
  81. font-weight: bold;
  82. color: #2c3e50;
  83. }
  84. nav a.router-link-exact-active {
  85. color: #42b983;
  86. }
  87. </style>