Commit c69f8ff5fb8b7557cfd718f2718511e2cacab52a

Authored by 梁灏
1 parent 2b98434e

update Anchor

src/components/anchor/anchor-link.vue
@@ -5,9 +5,9 @@ @@ -5,9 +5,9 @@
5 </div> 5 </div>
6 </template> 6 </template>
7 <script> 7 <script>
8 -import { findComponentUpward } from '../../utils/assist';  
9 export default { 8 export default {
10 name: 'AnchorLink', 9 name: 'AnchorLink',
  10 + inject: ['anchorCom'],
11 props: { 11 props: {
12 href: String, 12 href: String,
13 title: String 13 title: String
@@ -21,29 +21,23 @@ export default { @@ -21,29 +21,23 @@ export default {
21 anchorLinkClasses () { 21 anchorLinkClasses () {
22 return [ 22 return [
23 this.prefix, 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 linkTitleClasses () { 27 linkTitleClasses () {
28 return [ 28 return [
29 `${this.prefix}-title` 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 methods: { 33 methods: {
40 goAnchor () { 34 goAnchor () {
41 - this.parentAnchor.turnTo(this.href); 35 + this.anchorCom.turnTo(this.href);
42 } 36 }
43 }, 37 },
44 mounted () { 38 mounted () {
45 this.$nextTick(() => { 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,6 +15,11 @@ import { scrollTop, findComponentDownward, findComponentsDownward, sharpMatcherR
15 import { on, off } from '../../utils/dom'; 15 import { on, off } from '../../utils/dom';
16 export default { 16 export default {
17 name: 'Anchor', 17 name: 'Anchor',
  18 + provide () {
  19 + return {
  20 + anchorCom: this
  21 + };
  22 + },
18 data () { 23 data () {
19 return { 24 return {
20 prefix: 'ivu-anchor', 25 prefix: 'ivu-anchor',