Skip to content

Commit d591e4b

Browse files
authored
feat: update anchor (#2373)
1 parent 4ef17f8 commit d591e4b

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

components/anchor/Anchor.jsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inject } from 'vue';
12
import PropTypes from '../_util/vue-types';
23
import classNames from 'classnames';
34
import addEventListener from '../vc-util/Dom/addEventListener';
@@ -98,8 +99,10 @@ export default {
9899
showInkInFixed: false,
99100
getContainer: getDefaultContainer,
100101
}),
101-
inject: {
102-
configProvider: { default: () => ConfigConsumerProps },
102+
setup() {
103+
return {
104+
configProvider: inject('configProvider', ConfigConsumerProps),
105+
};
103106
},
104107
data() {
105108
this.links = [];
@@ -294,7 +297,7 @@ export default {
294297
<div class={`${prefixCls}-ink`}>
295298
<span class={inkClass} ref="inkNode" />
296299
</div>
297-
{$slots.default}
300+
{$slots.default && $slots.default()}
298301
</div>
299302
</div>
300303
);

components/anchor/AnchorLink.jsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { inject } from 'vue';
12
import PropTypes from '../_util/vue-types';
2-
import { initDefaultProps, getComponentFromProp } from '../_util/props-util';
3+
import { initDefaultProps, getComponent } from '../_util/props-util';
34
import classNames from 'classnames';
45
import { ConfigConsumerProps } from '../config-provider';
56

@@ -15,10 +16,12 @@ export default {
1516
props: initDefaultProps(AnchorLinkProps, {
1617
href: '#',
1718
}),
18-
inject: {
19-
antAnchor: { default: () => ({}) },
20-
antAnchorContext: { default: () => ({}) },
21-
configProvider: { default: () => ConfigConsumerProps },
19+
setup() {
20+
return {
21+
antAnchor: inject('antAnchor', {}),
22+
antAnchorContext: inject('antAnchorContext', {}),
23+
configProvider: inject('configProvider', ConfigConsumerProps),
24+
};
2225
},
2326
watch: {
2427
href(val, oldVal) {
@@ -53,7 +56,7 @@ export default {
5356
const getPrefixCls = this.configProvider.getPrefixCls;
5457
const prefixCls = getPrefixCls('anchor', customizePrefixCls);
5558

56-
const title = getComponentFromProp(this, 'title');
59+
const title = getComponent(this, 'title');
5760
const active = this.antAnchor.$data.activeLink === href;
5861
const wrapperClassName = classNames(`${prefixCls}-link`, {
5962
[`${prefixCls}-link-active`]: active,
@@ -72,7 +75,7 @@ export default {
7275
>
7376
{title}
7477
</a>
75-
{$slots.default}
78+
{$slots.default && $slots.default()}
7679
</div>
7780
);
7881
},

components/anchor/index.jsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import Anchor from './Anchor';
22
import AnchorLink from './AnchorLink';
3-
import Base from '../base';
43

54
Anchor.Link = AnchorLink;
65

76
/* istanbul ignore next */
8-
Anchor.install = function(Vue) {
9-
Vue.use(Base);
10-
Vue.component(Anchor.name, Anchor);
11-
Vue.component(Anchor.Link.name, Anchor.Link);
7+
Anchor.install = function(app) {
8+
app.component(Anchor.name, Anchor);
9+
app.component(Anchor.Link.name, Anchor.Link);
1210
};
1311
export { AnchorProps } from './Anchor';
1412
export { AnchorLinkProps } from './AnchorLink';

examples/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Drawer from 'ant-design-vue/drawer';
88
import Affix from 'ant-design-vue/affix';
99
import Alert from 'ant-design-vue/alert';
1010
import Divider from 'ant-design-vue/divider';
11+
import Anchor from 'ant-design-vue/anchor';
1112
import ConfigProvider from 'ant-design-vue/config-provider';
1213
import Result from 'ant-design-vue/result';
1314
import Spin from 'ant-design-vue/spin';
@@ -25,6 +26,7 @@ createApp(App)
2526
.use(Alert)
2627
.use(Divider)
2728
.use(Result)
29+
.use(Anchor)
2830
.use(Spin)
2931
.use(Empty)
3032
.use(Timeline)

0 commit comments

Comments
 (0)