Blame view

src/components/anchor/anchor-link.vue 1.4 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
17
18
19
          title: String,
          scrollOffset: {
              type: Number,
              default () {
                  return this.anchorCom.scrollOffset
              }
          }
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;
7ff2f71a   zhigang.li   fix
42
43
44
45
46
47
48
              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
49
          }
4556cfa8   zhigang.li   fixed bug of anch...
50
51
52
      },
      mounted () {
          this.$nextTick(() => {
c69f8ff5   梁灏   update Anchor
53
              this.anchorCom.init();
4556cfa8   zhigang.li   fixed bug of anch...
54
          });
43513f70   zhigang.li   add anchor component
55
56
57
      }
  };
  </script>