javascript - 如何解决此错误“TypeError:无法解构'undefined'的属性'image',因为它是未定义的”?下面是我的代码-
问题描述
React Js 我收到以下错误-“TypeError:无法解构'undefined'的属性'image',因为它是未定义的”?下面是我的代码“我该如何解决这个问题,为什么它显示未定义是我定义的方式是正确的.....?
有人可以帮忙吗?
下面是 React JS 中的代码
import React from 'react';
// import profile from '../assets/rocket.svg';
import styled from 'styled-components';
import { useSpring, animated, config } from 'react-spring';
import "../css/Card.css"
const Container = styled(animated.div)`
display: inline-block;
padding: 0em;
background: #C7D2FE66;
border-radius: 10px;
z-index: 1;
position: relative;
backdrop-filter: blur(10px);
border: 2px solid transparent;
background-clip: border-box;
// cursor: pointer;
`;
const StyledImg = styled.img`
width: 500px;
height:auto;
// height: auto;
border: 2px solid #000;
// border-radius: 50%;
`;
const StyledH1 = styled.h1`
line-heright: 1.5;
letter-spacing: 1.5;
font-family: "Gilroy";
`;
const StyledH3 = styled.h3`
line-heright: 1.5;
letter-spacing: 1.15;
font-family: "Gilroy";
font-size: 20px;
`;
const calc = (x, y) => [-(y - window.innerHeight / 2) / 20, (x - window.innerWidth / 2) / 20, 1]
const trans = (x, y, s) => `perspective(600px) rotateX(${x}deg) rotateY(${y}deg) scale(${s})`
function Card({ heading }, { description }, { image }) {
const [props, set] = useSpring(() => ({ xys: [0, 0, 1], config: config.default }))
return (
<Container
onMouseMove={({ clientX: x, clientY: y }) => (set({ xys: calc(x, y) }))}
onMouseLeave={() => set({ xys: [0, 0, 1] })}
style={{
transform: props.xys.interpolate(trans)
}}
>
<StyledH1>{heading}</StyledH1>
<StyledH3>{description} <br /> </StyledH3>
<StyledImg src={image} />
</Container>
);
}
export default Card;
```
解决方案
推荐阅读
- javascript - 在 LocalStorage 中覆盖了添加的重复数据
- ionic-framework - ion-segment-button 指示器轮廓边框
- python - 查找“类别”列的平均值?
- c# - 无法在 C# 中以编程方式填充 Form.CheckBox 数组
- c - 如何通过 Visual Studio Code 检查整个项目的 C 代码错误?
- mongodb - Mongo 永久 oplog,永久 Change Stream 可恢复性
- php - 在 null LARAVEL 8 上调用成员函数锦标赛()
- java - 收件人列表中的 Apache 骆驼通行证标头
- javascript - Javascript在容器中拖放文件:如何防止`dragover`被多次调用导致延迟?
- r - 如何将“left_join”与同一数据框中的多个列一起使用?