use link.js for anchor
This commit is contained in:
parent
2525733729
commit
576329cc63
3 changed files with 15 additions and 17 deletions
|
@ -5,9 +5,11 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import mixinsLink from '../../mixins/link';
|
||||
export default {
|
||||
name: 'AnchorLink',
|
||||
inject: ['anchorCom'],
|
||||
mixins: [ mixinsLink ],
|
||||
props: {
|
||||
href: String,
|
||||
title: String
|
||||
|
@ -31,8 +33,10 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
goAnchor () {
|
||||
this.anchorCom.turnTo(this.href);
|
||||
goAnchor (event) {
|
||||
this.currentLink = this.href;
|
||||
this.$emit('on-select', this.href);
|
||||
this.handleCheckClick(event);
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
|
|
|
@ -25,7 +25,6 @@ export default {
|
|||
prefix: 'ivu-anchor',
|
||||
isAffixed: false, // current affixed state
|
||||
inkTop: 0,
|
||||
linkHeight: 0,
|
||||
animating: false, // if is scrolling now
|
||||
currentLink: '', // current show link => #href -> currentLink = #href
|
||||
currentId: '', // current show title id => #href -> currentId = href
|
||||
|
@ -83,13 +82,6 @@ export default {
|
|||
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop || e.target.scrollTop;
|
||||
this.getCurrentScrollAtTitleId(scrollTop);
|
||||
},
|
||||
turnTo (href) {
|
||||
this.currentLink = href;
|
||||
this.$router.push({
|
||||
path: href
|
||||
});
|
||||
this.$emit('on-select', href);
|
||||
},
|
||||
handleHashChange () {
|
||||
const url = window.location.href;
|
||||
const sharpLinkMatch = sharpMatcherRegx.exec(url);
|
||||
|
@ -159,8 +151,7 @@ export default {
|
|||
off(window, 'hashchange', this.handleHashChange);
|
||||
},
|
||||
init () {
|
||||
const anchorLink = findComponentDownward(this, 'AnchorLink');
|
||||
this.linkHeight = anchorLink ? anchorLink.$el.getBoundingClientRect().height : 0;
|
||||
// const anchorLink = findComponentDownward(this, 'AnchorLink');
|
||||
this.handleHashChange();
|
||||
this.$nextTick(() => {
|
||||
this.removeListener();
|
||||
|
@ -178,7 +169,9 @@ export default {
|
|||
watch: {
|
||||
'$route' () {
|
||||
this.handleHashChange();
|
||||
this.$nextTick(() => {
|
||||
this.handleScrollTo();
|
||||
})
|
||||
},
|
||||
container () {
|
||||
this.init();
|
||||
|
|
|
@ -26,14 +26,15 @@ export default {
|
|||
methods: {
|
||||
handleClick () {
|
||||
const isRoute = this.$router;
|
||||
let href = this.to || this.href;
|
||||
if (isRoute) {
|
||||
this.replace ? this.$router.replace(this.to) : this.$router.push(this.to);
|
||||
this.replace ? this.$router.replace(href) : this.$router.push(href);
|
||||
} else {
|
||||
window.location.href = this.to;
|
||||
window.location.href = href;
|
||||
}
|
||||
},
|
||||
handleCheckClick (event) {
|
||||
if (this.to) {
|
||||
if (this.to || this.href) {
|
||||
if (this.target === '_blank') {
|
||||
return false;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue