首页 > 解决方案 > vscode中使用antd框架的按钮提示

问题描述

我在 vscode 中使用 antd 的 Button 和 Input。但它在 Button 上显示错误,我想知道原因。

我试过输入,它没有显示错误。如图所示。

import React from 'react';
import styles from './index.css';
import router from 'umi/router';
import {Input, Button} from 'antd';

export default function() {
  const handleClick=()=>{
    router.push('/homepage/');
  }
  return (
    <div className={styles.normal}>
      <div className={styles.welcome} />
      <h1 className={styles.title}>login</h1>
      <ul className={styles.list}>
        <li><label>username:</label><Input className={styles.input} placeholder="username"/></li>
        <li><label>password:</label><Input className={styles.input} placeholder="password"/></li>
        <li>
          <Button type="primary" shape="round" onClick={handleClick}>login</Button>
        </li>
      </ul>
    </div>
  );
}

实际输出显示:

<--language:lang-none-->
"message": "Type '{ children: string; type: \"primary\"; shape: \"round\"; onClick: () => void; }' is missing the following properties from type 'Pick<Pick<(Readonly<AnchorButtonProps> & Readonly<{ children?: ReactNode; }>) | (Readonly<NativeButtonProps> & Readonly<{ children?: ReactNode; }>), \"defaultChecked\" | \"defaultValue\" | ... 257 more ... | \"block\"> & Pick<...> & Pick<...>, \"defaultChecked\" | ... 256 more ... | \"shape\">': defaultChecked, defaultValue, suppressContentEditableWarning, suppressHydrationWarning, and 250 more."

另外,我想问一下如何使用静态资源?示例项目只是使用 css 背景 url 的方式来展示图片。

在此处输入图像描述

标签: reactjstypescriptvisual-studio-codeantd

解决方案


您好,我已在 package.json 中将 @types/react 更新为 16.8.11。这解决了我的问题。


推荐阅读