首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不应用于React中的组件的样式

不应用于React中的组件的样式
EN

Stack Overflow用户
提问于 2022-10-20 03:39:26
回答 1查看 51关注 0票数 -2

我想用盒子里的道具来塑造我的形象。我不知道这个物体是不是空的。

代码语言:javascript
复制
const FaceRecognition = ({ imageUrl, box }) => {
  return (enter image description here
    <div>
      <img id='fa[enter image description here][1]ce' src={imageUrl} width={"500px"} height={"auto"} />
      <div
        className='bounding-box'
        style={{
          top: box.topRow,
          right: box.rightCol,
          bottom: box.bottomCol,
          left: box.leftCol,
        }}
      ></div>
    </div>
  );
};

 displayFaceBox = (box) => {
    this.setState({ box: box });
   
  };

这是我的App类中的代码,我想在其中呈现所有内容。

代码语言:javascript
复制
calculateFaceLocation = (data) => {
    const clarifaiFace =
      
    const image = document.getElementById("face");
    const width = Number(image.width);
    const height = Number(image.height);
   
    return {
      leftCol: clarifaiFace.left_col * width,
      topRow: clarifaiFace.top_row * height,
      rightCol: width - (clarifaiFace.right - width),
      bottomCol: height - (clarifaiFace.right - height),
    };
  };
  displayFaceBox = (box) => {
    this.setState({ box: box });
    console.log(this.state.box);
  };
EN

回答 1

Stack Overflow用户

发布于 2022-10-20 03:46:25

当将对象作为对象传递给函数组件时,必须使用JSON.stringify序列化它,如下所示:

代码语言:javascript
复制
displayFaceBox = (box) => {
    this.setState({ box: JSON.stringify(box) });
    console.log(this.state.box);
};

然后在函数组件中解析它,如下所示。

代码语言:javascript
复制
const FaceRecognition = ({ imageUrl, box }) => {
     box = JSON.parse(box)
    ...

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74134177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档