reactjs - 为什么 1 加载资源失败:服务器响应状态为 431(请求标头字段太大):3000/api/posts?:发生?
问题描述
帖子里有错误。我用f12检查过,它一直在犯这样的错误。你认为为什么会这样?我想知道这种错误通常何时出现。帖子中有错误。我用f12检查过,它一直在犯这样的错误。你认为为什么会这样?我想知道这种错误通常何时出现。这是帖子代码
import React from 'react';
import styled from 'styled-components';
import Responsive from '../common/Responsive';
import Button from '../common/Button';
import palette from '../../lib/styles/palette';
import SubInfo from '../common/SubInfo';
import Tags from '../common/Tags';
import { Link } from 'react-router-dom';
const PostListBlock = styled(Responsive)`
margin-top: 3rem;
`;
const WritePostButtonWrapper = styled.div`
display: flex;
justify-content: flex-end;
margin-bottom: 3rem;
`;
const PostItemBlock = styled.div`
padding-top: 3rem;
padding-bottom: 3rem;
/* 맨 위 포스트는 padding-top 없음 */
&:first-child {
padding-top: 0;
}
& + & {
border-top: 1px solid ${palette.gray[2]};
}
h2 {
font-size: 2rem;
margin-bottom: 0;
margin-top: 0;
&:hover {
color: ${palette.gray[6]};
}
}
p {
margin-top: 2rem;
}
`;
const PostItem = ({ post }) => {
const { publishedDate, user, tags, title, body, _id } = post;
return (
<PostItemBlock>
<h2>
<Link to={`/@${user.username}/${_id}`}>{title}</Link>
</h2>
<SubInfo
username={user.username}
publishedDate={new Date(publishedDate)}
/>
<Tags tags={tags} />
<p>{body}</p>
</PostItemBlock>
);
};
const PostList = ({ posts, loading, error, showWriteButton }) => {
// 에러 발생 시
if (error) {
return <PostListBlock>에러가 발생했습니다.</PostListBlock>;
}
return (
<PostListBlock>
<WritePostButtonWrapper>
{showWriteButton && (
<Button cyan to="/write">
새 글 작성하기
</Button>
)}
</WritePostButtonWrapper>
{/* 로딩 중 아니고, 포스트 배열이 존재할 때만 보여줌 */}
{!loading && posts && (
<div>
{posts.map(post => (
<PostItem post={post} key={post._id} />
))}
</div>
)}
</PostListBlock>
);
};
导出默认 PostList;
解决方案
推荐阅读
- pine-script - 是否可以在 y 轴上标注价格?
- javascript - 运行此javascript时是否可以分配打印机?
- angular - 如何使用 Null 作为值 Angular Material Select
- php - Codeigniter 数据库未显示在视图中
- angular - 为什么用户登录时 AuthGuard 中的 ReplaySubject 无法按预期工作?角度 10+
- javascript - 不和谐.JS | 如何创建一个专门在 [] 下的参数
- node.js - 如何在函数中获取对象数据并将其传递给nodejs中的不同函数
- c++ - 如何在没有额外副本的情况下从 std::map 安全地“pop-front”?
- javascript - 自定义配置底部导航
- javascript - 如何使 HTML 网站具有交互性,以便当用户单击删除按钮时它会为所有用户更改,即使您重新加载也是如此?