mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 21:50:07 +08:00
62 lines
1.4 KiB
React
62 lines
1.4 KiB
React
|
import PropTypes from '../_util/vue-types'
|
||
|
import { initDefaultProps, getComponentFromProp } from '../_util/props-util'
|
||
|
import classNames from 'classnames'
|
||
|
|
||
|
export const AnchorLinkProps = {
|
||
|
prefixCls: PropTypes.string,
|
||
|
href: PropTypes.string,
|
||
|
title: PropTypes.any,
|
||
|
}
|
||
|
|
||
|
export default {
|
||
|
name: 'AAnchorLink',
|
||
|
props: initDefaultProps(AnchorLinkProps, {
|
||
|
prefixCls: 'ant-anchor',
|
||
|
href: '#',
|
||
|
}),
|
||
|
inject: {
|
||
|
antAnchor: { default: {}},
|
||
|
},
|
||
|
|
||
|
mounted () {
|
||
|
this.antAnchor.registerLink(this.href)
|
||
|
},
|
||
|
|
||
|
beforeDestroy () {
|
||
|
this.antAnchor.unregisterLink(this.href)
|
||
|
},
|
||
|
methods: {
|
||
|
handleClick () {
|
||
|
this.antAnchor.scrollTo(this.href)
|
||
|
},
|
||
|
},
|
||
|
render () {
|
||
|
const {
|
||
|
prefixCls,
|
||
|
href,
|
||
|
$slots,
|
||
|
} = this
|
||
|
const title = getComponentFromProp(this, 'title')
|
||
|
const active = this.antAnchor.$data.activeLink === href
|
||
|
const wrapperClassName = classNames(`${prefixCls}-link`, {
|
||
|
[`${prefixCls}-link-active`]: active,
|
||
|
})
|
||
|
const titleClassName = classNames(`${prefixCls}-link-title`, {
|
||
|
[`${prefixCls}-link-title-active`]: active,
|
||
|
})
|
||
|
return (
|
||
|
<div class={wrapperClassName}>
|
||
|
<a
|
||
|
class={titleClassName}
|
||
|
href={href}
|
||
|
title={typeof title === 'string' ? title : ''}
|
||
|
onClick={this.handleClick}
|
||
|
>
|
||
|
{title}
|
||
|
</a>
|
||
|
{$slots.default}
|
||
|
</div>
|
||
|
)
|
||
|
},
|
||
|
}
|