123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <template>
- <div class="app-page">
- <h2>{{ curRule.label }}页签规则</h2>
- <p>你在 <strong class="text-strong">{{ pageTime }}</strong> 秒前打开本页面</p>
- <table class="demo-table">
- <tr>
- <th>规则类型</th>
- <td>{{ curRule.type }}</td>
- </tr>
- <tr>
- <th>实现方法</th>
- <td class="rule-fn">
- {{ curRule.fn }}
- </td>
- </tr>
- <tr>
- <th>规则说明</th>
- <td>{{ curRule.desc }}</td>
- </tr>
- </table>
- <h4>点击下面的链接,并观察页签的变化</h4>
- <ul class="btn-list">
- <li
- v-for="cat in catalogs"
- :key="cat"
- >
- <router-link
- v-for="t in types"
- :key="t"
- class="demo-btn"
- :to="`../${cat}/${t}`"
- >
- {{ cat }}/{{ t }}
- </router-link>
- <router-link
- class="demo-btn"
- :to="`../${cat}/1?q=abc`"
- >
- {{ cat }}/1?q=abc
- </router-link>
- <router-link
- class="demo-btn"
- :to="`../${cat}/1?q=def`"
- >
- {{ cat }}/1?q=def
- </router-link>
- </li>
- </ul>
- <h3>路由信息</h3>
- <page-route-info />
- </div>
- </template>
- <script>
- import pageTimer from '../mixins/pageTimer'
- import PageRouteInfo from '../components/PageRouteInfo'
- export default {
- name: 'Rule',
- components: { PageRouteInfo },
- mixins: [ pageTimer ],
- data () {
- let route = this.$route
- let { catalog, type } = route.params
- let ruleType = 'default'
- if (route.meta.aliveId) {
- ruleType = 'route'
- } else if (route.fullPath.indexOf('/global-rule/') > -1) {
- ruleType = 'global'
- }
- let rules = {
- default: {
- label: '默认',
- type: '内置规则:"path"',
- fn: 'route => route.path',
- desc: '相同route.params的路由共用页签'
- },
- global: {
- label: '全局',
- type: '内置规则:"fullPath"',
- fn: 'route => route.fullPath.replace(route.hash, \'\')',
- desc: '相同route.params和route.query的路由共用页签'
- },
- route: {
- label: '路由',
- type: '自定义规则',
- fn: 'route => \'route-rule/\' + route.params.catalog',
- desc: '相同catalog参数的路由共用页签'
- }
- }
- let curRule = rules[ruleType]
- return {
- curRule,
- catalog,
- type,
- catalogs: ['a', 'b', 'c'],
- types: [ 1, 2 ],
- link: { catalog, type },
- routeTab: `${curRule.label}规则${catalog}/${type}`
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .rule-fn {
- font-size: 1rem;
- font-style: italic;
- color: $color;
- }
- .btn-list {
- padding: 0;
- li {
- list-style: none;
- .demo-btn {
- margin-right: .5em;
- &:hover {
- color: $color-primary;
- border-color: $color-primary;
- }
- &.router-link-exact-active {
- color: #fff;
- background-color: $color-primary;
- border-color: rgba(0,0,0,.05);
- }
- }
- }
- }
- </style>
|