import React from 'react'; import { Box, Alert, AlertIcon, AlertTitle, AlertDescription, Button, VStack, Container } from '@chakra-ui/react'; class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, error: null, errorInfo: null }; } static getDerivedStateFromError(error) { return { hasError: true }; } componentDidCatch(error, errorInfo) { this.setState({ error: error, errorInfo: errorInfo }); } render() { if (this.state.hasError) { return ( 页面出现错误! 页面加载时发生了未预期的错误,请尝试刷新页面。 {process.env.NODE_ENV === 'development' && ( 错误详情: {this.state.error && this.state.error.toString()} {this.state.errorInfo.componentStack} )} ); } return this.props.children; } } export