【发布时间】:2020-04-29 20:56:56
【问题描述】:
我正在使用 Django 和 React 开发一个 Web 应用程序,我在一个 React 组件上构建了页面结构,它看起来很有效。 我有一个待办事项列表组件, 我有一个状态,其中包含待办事项列表的标题和项目。 然后当列表完成后,我想将待办事项列表发布到数据库中。
我面临的问题如下:
- 加载http://localhost:8000/
- 点击添加项目
- react 为新项目呈现新的空字段。持续一秒钟,页面刷新,链接变为
http://localhost:8000/?title=&dateCreation=&toDoItem=&when=&note=&toDoItem=&when=&note=
页面失去了状态,一切都像刚开始的状态
state = {
toDoList:{
title:"",
dateCreation:"",
toDoItems:[
{itemName:"",when: "", note:""},
]
}
}
addItemHandler = () => {
const toDoList = {...this.state.toDoList}
const toDoItems = [...this.state.toDoList.toDoItems]
toDoItems.push({itemName:"",when: "", note:""})
toDoList.toDoItems = toDoItems
return this.setState({toDoList: toDoList})
}
【问题讨论】:
标签: javascript django reactjs