Rule.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <div class="app-page">
  3. <h2>{{ curRule.label }}页签规则</h2>
  4. <p>你在 <strong class="text-strong">{{ pageTime }}</strong> 秒前打开本页面</p>
  5. <table class="demo-table">
  6. <tr>
  7. <th>规则类型</th>
  8. <td>{{ curRule.type }}</td>
  9. </tr>
  10. <tr>
  11. <th>实现方法</th>
  12. <td class="rule-fn">
  13. {{ curRule.fn }}
  14. </td>
  15. </tr>
  16. <tr>
  17. <th>规则说明</th>
  18. <td>{{ curRule.desc }}</td>
  19. </tr>
  20. </table>
  21. <h4>点击下面的链接,并观察页签的变化</h4>
  22. <ul class="btn-list">
  23. <li
  24. v-for="cat in catalogs"
  25. :key="cat"
  26. >
  27. <router-link
  28. v-for="t in types"
  29. :key="t"
  30. class="demo-btn"
  31. :to="`../${cat}/${t}`"
  32. >
  33. {{ cat }}/{{ t }}
  34. </router-link>
  35. <router-link
  36. class="demo-btn"
  37. :to="`../${cat}/1?q=abc`"
  38. >
  39. {{ cat }}/1?q=abc
  40. </router-link>
  41. <router-link
  42. class="demo-btn"
  43. :to="`../${cat}/1?q=def`"
  44. >
  45. {{ cat }}/1?q=def
  46. </router-link>
  47. </li>
  48. </ul>
  49. <h3>路由信息</h3>
  50. <page-route-info />
  51. </div>
  52. </template>
  53. <script>
  54. import pageTimer from '../mixins/pageTimer'
  55. import PageRouteInfo from '../components/PageRouteInfo'
  56. export default {
  57. name: 'Rule',
  58. components: { PageRouteInfo },
  59. mixins: [ pageTimer ],
  60. data () {
  61. let route = this.$route
  62. let { catalog, type } = route.params
  63. let ruleType = 'default'
  64. if (route.meta.aliveId) {
  65. ruleType = 'route'
  66. } else if (route.fullPath.indexOf('/global-rule/') > -1) {
  67. ruleType = 'global'
  68. }
  69. let rules = {
  70. default: {
  71. label: '默认',
  72. type: '内置规则:"path"',
  73. fn: 'route => route.path',
  74. desc: '相同route.params的路由共用页签'
  75. },
  76. global: {
  77. label: '全局',
  78. type: '内置规则:"fullPath"',
  79. fn: 'route => route.fullPath.replace(route.hash, \'\')',
  80. desc: '相同route.params和route.query的路由共用页签'
  81. },
  82. route: {
  83. label: '路由',
  84. type: '自定义规则',
  85. fn: 'route => \'route-rule/\' + route.params.catalog',
  86. desc: '相同catalog参数的路由共用页签'
  87. }
  88. }
  89. let curRule = rules[ruleType]
  90. return {
  91. curRule,
  92. catalog,
  93. type,
  94. catalogs: ['a', 'b', 'c'],
  95. types: [ 1, 2 ],
  96. link: { catalog, type },
  97. routeTab: `${curRule.label}规则${catalog}/${type}`
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .rule-fn {
  104. font-size: 1rem;
  105. font-style: italic;
  106. color: $color;
  107. }
  108. .btn-list {
  109. padding: 0;
  110. li {
  111. list-style: none;
  112. .demo-btn {
  113. margin-right: .5em;
  114. &:hover {
  115. color: $color-primary;
  116. border-color: $color-primary;
  117. }
  118. &.router-link-exact-active {
  119. color: #fff;
  120. background-color: $color-primary;
  121. border-color: rgba(0,0,0,.05);
  122. }
  123. }
  124. }
  125. }
  126. </style>