types(Sidebar): use tsx (#8121)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { createNamespace } from '../utils';
|
||||
import { useParent } from '@vant/use';
|
||||
import { useRoute, routeProps } from '../composables/use-route';
|
||||
import { SIDEBAR_KEY } from '../sidebar';
|
||||
import { SIDEBAR_KEY, SidebarProvide } from '../sidebar';
|
||||
import Badge from '../badge';
|
||||
|
||||
const [createComponent, bem] = createNamespace('sidebar-item');
|
||||
@@ -19,7 +19,16 @@ export default createComponent({
|
||||
|
||||
setup(props, { emit, slots }) {
|
||||
const route = useRoute();
|
||||
const { parent, index } = useParent(SIDEBAR_KEY);
|
||||
const { parent, index } = useParent<SidebarProvide>(SIDEBAR_KEY);
|
||||
|
||||
if (!parent) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.error(
|
||||
'[Vant] SidebarItem must be a child component of Sidebar.'
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const onClick = () => {
|
||||
if (props.disabled) {
|
||||
@@ -27,14 +36,13 @@ export default createComponent({
|
||||
}
|
||||
|
||||
emit('click', index.value);
|
||||
parent.emit('update:modelValue', index.value);
|
||||
parent.setActive(index.value);
|
||||
route();
|
||||
};
|
||||
|
||||
return () => {
|
||||
const { dot, badge, title, disabled } = props;
|
||||
const selected = index.value === parent.active();
|
||||
const selected = index.value === parent.getActive();
|
||||
|
||||
return (
|
||||
<a class={bem({ select: selected, disabled })} onClick={onClick}>
|
||||
Reference in New Issue
Block a user