小编aza*_*026的帖子

如何在React中使用axios删除单个项目

我已经研究了许多类似这样的文章和帖子,但在我的情况下不起作用,我只需要使用axios从我的应用程序中的帖子列表中删除一个项目即可。在axios文档中,它说您需要将参数传递给delete方法。另外,在大多数应用程序中,我都使用过ID,而ID却没有处于状态。但是我不能让它工作。请查看我的整个代码。我知道我的删除方法有误,请帮助我修复它:

    // The individual post component
    const Post = props => (
    <article className="post">
        <h2 className="post-title">{props.title}</h2>
        <hr />
        <p className="post-content">{props.content}</p>
        <button onClick={props.delete}>Delete this post</button>
    </article>
);

// The seperate form component to be written later

class Form extends React.Component {}

// The posts loop component

class Posts extends React.Component {
    state = {
        posts: [],
        post: {
            title: "",
            content: ""
        }
        // error:false
    };

    componentDidMount() {
        const { posts } = this.state;
        axios
            .get("url")
            .then(response => { …
Run Code Online (Sandbox Code Playgroud)

firebase reactjs axios

0
推荐指数
1
解决办法
4486
查看次数

标签 统计

axios ×1

firebase ×1

reactjs ×1