Blame view

src/components/anchor/anchor-link.vue 1.49 KB
43513f70   zhigang.li   add anchor component
1
2
  <template>
  	<div :class="anchorLinkClasses">
145be7a6   zhigang.li   anchor-link组件添加sc...
3
          <a :class="linkTitleClasses" :href="href" :data-scroll-offset="scrollOffset" :data-href="href" @click.prevent="goAnchor" :title="title">{{ title }}</a>
43513f70   zhigang.li   add anchor component
4
5
6
7
          <slot></slot>
      </div>
  </template>
  <script>
43513f70   zhigang.li   add anchor component
8
9
  export default {
      name: 'AnchorLink',
c69f8ff5   梁灏   update Anchor
10
      inject: ['anchorCom'],
43513f70   zhigang.li   add anchor component
11
12
      props: {
          href: String,
145be7a6   zhigang.li   anchor-link组件添加sc...
13
14
15
16
          title: String,
          scrollOffset: {
              type: Number,
              default () {
be772972   梁灏   update Time
17
                  return this.anchorCom.scrollOffset;
145be7a6   zhigang.li   anchor-link组件添加sc...
18
19
              }
          }
43513f70   zhigang.li   add anchor component
20
21
22
23
24
25
26
27
28
29
      },
      data () {
          return {
              prefix: 'ivu-anchor-link'
          };
      },
      computed: {
          anchorLinkClasses () {
              return [
                  this.prefix,
c69f8ff5   梁灏   update Anchor
30
                  this.anchorCom.currentLink === this.href ? `${this.prefix}-active` : ''
43513f70   zhigang.li   add anchor component
31
32
33
34
35
36
              ];
          },
          linkTitleClasses () {
              return [
                  `${this.prefix}-title`
              ];
43513f70   zhigang.li   add anchor component
37
38
39
          }
      },
      methods: {
7ff2f71a   zhigang.li   fix
40
          goAnchor () {
576329cc   zhigang.li   use link.js for a...
41
              this.currentLink = this.href;
93896627   zhigang.li   修复点击anchor-link后再...
42
43
              this.anchorCom.handleHashChange();
              this.anchorCom.handleScrollTo();
7ff2f71a   zhigang.li   fix
44
45
46
47
48
49
50
              this.anchorCom.$emit('on-select', this.href);
              const isRoute = this.$router;
              if (isRoute) {
                  this.$router.push(this.href);
              } else {
                  window.location.href = this.href;
              }
43513f70   zhigang.li   add anchor component
51
          }
4556cfa8   zhigang.li   fixed bug of anch...
52
53
54
      },
      mounted () {
          this.$nextTick(() => {
c69f8ff5   梁灏   update Anchor
55
              this.anchorCom.init();
4556cfa8   zhigang.li   fixed bug of anch...
56
          });
43513f70   zhigang.li   add anchor component
57
58
59
      }
  };
  </script>