Blame view

src/components/anchor/anchor-link.vue 1.21 KB
43513f70   zhigang.li   add anchor component
1
2
  <template>
  	<div :class="anchorLinkClasses">
3fe51bfc   梁灏   update Anchor
3
          <a :class="linkTitleClasses" :href="href" :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
13
14
15
16
17
18
19
20
21
22
23
      props: {
          href: String,
          title: String
      },
      data () {
          return {
              prefix: 'ivu-anchor-link'
          };
      },
      computed: {
          anchorLinkClasses () {
              return [
                  this.prefix,
c69f8ff5   梁灏   update Anchor
24
                  this.anchorCom.currentLink === this.href ? `${this.prefix}-active` : ''
43513f70   zhigang.li   add anchor component
25
26
27
28
29
30
              ];
          },
          linkTitleClasses () {
              return [
                  `${this.prefix}-title`
              ];
43513f70   zhigang.li   add anchor component
31
32
33
          }
      },
      methods: {
7ff2f71a   zhigang.li   fix
34
          goAnchor () {
576329cc   zhigang.li   use link.js for a...
35
              this.currentLink = this.href;
7ff2f71a   zhigang.li   fix
36
37
38
39
40
41
42
              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
43
          }
4556cfa8   zhigang.li   fixed bug of anch...
44
45
46
      },
      mounted () {
          this.$nextTick(() => {
c69f8ff5   梁灏   update Anchor
47
              this.anchorCom.init();
4556cfa8   zhigang.li   fixed bug of anch...
48
          });
43513f70   zhigang.li   add anchor component
49
50
51
      }
  };
  </script>