axios put请求不要修改数据

时间:2018-01-22 16:55:20

标签: javascript reactjs firebase-realtime-database axios

我有简单的待办事项应用程序,并在该待办事项目中有checlbox。当我检查它时,我发送put请求到firebase数据库指定todo的id和状态“true(所以它将被检查)。但我得到响应空todo和检查todo也变空了

handleCheckTodo(id){
    const todo ={
      id,      
      status: true
    };
    axios.put('https://react-todo-app-XXXXX.firebaseio.com/todos.json', todo).then(res => {
      console.log(res);
    }).catch(err => {
            console.log(err);            
        }
    );
  }

这是我的待办事项结构:

const todo = {
      id: Math.random().toString(16).slice(2),
      name: todoName.value,
      body: todoDesription.value,
      status: false
    }    

创建待办事项:

  addTodo(todoName, todoDesription) {
    console.log(todoName.value, todoDesription.value);
    const todo = {
      id: Math.random().toString(16).slice(2),
      name: todoName.value,
      body: todoDesription.value,
      status: false
    }    
    axios.post('https://react-todo-app-4b652.firebaseio.com/todos.json', todo).then(res => {
      console.log(res);
    }).catch(err => {
            console.log(err);            
        }
    );
  }

0 个答案:

没有答案