代码之家  ›  专栏  ›  技术社区  ›  StuiterSlurf Marius

有什么反应…吗?

  •  1
  • StuiterSlurf Marius  · 技术社区  · 7 年前

    to 到的链接组件 react-router-dom material-ui core

    我终于想出了这个解决方案:

    import * as React from 'react';
    import Tabs from '@material-ui/core/Tabs';
    import Tab from '@material-ui/core/Tab';
    import { Link } from 'react-router-dom';
    
    interface Props { 
      title?: string;
    }
    interface State {
       value: number;
    }
    
    class NavButtons extends React.Component<Props, State>  {
       constructor(props: Props) {
          super(props);
          this.state = { value: 0 };
       }
    
       public handleOnChange = (event: any, value: number) => {
          this.setState({ value })
       }
    
       public render() {
    
          const {value} = this.state
    
          return (
            <Tabs value={value} onChange={this.handleOnChange} >
              <Tab label="Home" component={Link} {...{to:"/"} as any} />
              <Tab label="Contact" component={Link} {...{to:"/contact/"} as any} />
            </Tabs>
          )
       }
    }
    
    export default NavButtons
    

    ...{} as any 在材料UI或React的文档中执行。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Marson Mao    7 年前

    typescript. what is mean: (this as any)

    似乎是一种类型脚本语法。正在添加 as any {to:"/"}