在一些场景中,我们可能需要在不同的地方传入不同的事件到子组件中去触发
{}
<MyNavBar title={'首页'}
rightText={'查看记录'}
onClickRight={handlerClickRight}/>
function handlerClickRight() {
history.push({
pathname: '/other'
})
}
import React from "react";
import {NavBar} from "react-vant";
export default function MyNavBar(props: {
title?: string;
rightText?: string;
onClickRight?: () => void;
}) {
return (
<>
<NavBar
title={props.title}
leftArrow={true}
safeAreaInsetTop={true}
border={false}
placeholder={true}
rightText={props.rightText}
onClickRight={props.onClickRight}
/>
</>
)
}