Commit c69f8ff5fb8b7557cfd718f2718511e2cacab52a
1 parent
2b98434e
update Anchor
Showing
2 changed files
with
9 additions
and
10 deletions
Show diff stats
src/components/anchor/anchor-link.vue
| ... | ... | @@ -5,9 +5,9 @@ |
| 5 | 5 | </div> |
| 6 | 6 | </template> |
| 7 | 7 | <script> |
| 8 | -import { findComponentUpward } from '../../utils/assist'; | |
| 9 | 8 | export default { |
| 10 | 9 | name: 'AnchorLink', |
| 10 | + inject: ['anchorCom'], | |
| 11 | 11 | props: { |
| 12 | 12 | href: String, |
| 13 | 13 | title: String |
| ... | ... | @@ -21,29 +21,23 @@ export default { |
| 21 | 21 | anchorLinkClasses () { |
| 22 | 22 | return [ |
| 23 | 23 | this.prefix, |
| 24 | - this.currentLink === this.href ? `${this.prefix}-active` : '' | |
| 24 | + this.anchorCom.currentLink === this.href ? `${this.prefix}-active` : '' | |
| 25 | 25 | ]; |
| 26 | 26 | }, |
| 27 | 27 | linkTitleClasses () { |
| 28 | 28 | return [ |
| 29 | 29 | `${this.prefix}-title` |
| 30 | 30 | ]; |
| 31 | - }, | |
| 32 | - parentAnchor () { | |
| 33 | - return findComponentUpward(this, 'Anchor'); | |
| 34 | - }, | |
| 35 | - currentLink () { | |
| 36 | - return this.parentAnchor.currentLink; | |
| 37 | 31 | } |
| 38 | 32 | }, |
| 39 | 33 | methods: { |
| 40 | 34 | goAnchor () { |
| 41 | - this.parentAnchor.turnTo(this.href); | |
| 35 | + this.anchorCom.turnTo(this.href); | |
| 42 | 36 | } |
| 43 | 37 | }, |
| 44 | 38 | mounted () { |
| 45 | 39 | this.$nextTick(() => { |
| 46 | - this.parentAnchor.init(); | |
| 40 | + this.anchorCom.init(); | |
| 47 | 41 | }); |
| 48 | 42 | } |
| 49 | 43 | }; | ... | ... |
src/components/anchor/anchor.vue
| ... | ... | @@ -15,6 +15,11 @@ import { scrollTop, findComponentDownward, findComponentsDownward, sharpMatcherR |
| 15 | 15 | import { on, off } from '../../utils/dom'; |
| 16 | 16 | export default { |
| 17 | 17 | name: 'Anchor', |
| 18 | + provide () { | |
| 19 | + return { | |
| 20 | + anchorCom: this | |
| 21 | + }; | |
| 22 | + }, | |
| 18 | 23 | data () { |
| 19 | 24 | return { |
| 20 | 25 | prefix: 'ivu-anchor', | ... | ... |