一个属性引发的React报错:The above error occurred in the component

程序运行报错:

devScripts.js:6523 The above error occurred in the <div> component:

    at div
    at IndexPage
    at IndexPage
    at div
    at IndexPage
    at LoadableComponent (http://localhost:8130/mf-dep_vendors-node_modules_babel_runtime_helpers_esm_extends_js-node_modules_babel_runtime_helpers_-424ef3.f230f37e.async.js:474:68)
    at Route
...

代码部分:

import React from 'react';
import styles from './index.less';

const IndexPage: React.FC<{}> = () => {
  return (
    <div className={styles.titleHead}>
      <div className={styles.titleName}>板块</div>
      <div className={styles.titleInfo}>
        <div className={styles.tabControl}>
          <div style={styles.tabItem}>累计</div>

        </div>
      </div>
    </div>
  );
};
export default IndexPage;

很难发现,累计一行, div 属性应该是 className ,这里错写成了 style 所以引发了报错。

style 的属性应该是一个 {}

未经允许不得转载:Web前端开发资源网 » 一个属性引发的React报错:The above error occurred in the component

推荐阅读:

Vue.js学习笔记——条件、循环、双向绑定

JavaScript的引入方式和基本属性

判断网页是通过PC端还是移动终端打开的

html中hr标签的基础知识

Z-Blog 搜索报错:Cannot pass parameter 1 by reference 解决方法

赞 (0)
分享到: +

评论 沙发

Avatar

换个身份

  • 昵称 (必填)
  • 邮箱 (选填)