【问题标题】:Empty data in response with axios and vuex使用 axios 和 vuex 响应的空数据
【发布时间】:2021-10-07 19:18:45
【问题描述】:

当我用 axios 发送这个补丁请求时,后端接收到数据,但是 response.data 回来是空的。请和谢谢!

// ACTION IN VUEX STORE
async updateMe({ commit }, payload) {
  let id = localStorage.getItem('userId');
  let user = { name: payload.name, email: payload.email, id: id };
  try {
    const response = await axios.patch(
      `http://localhost:3000/api/v1/users/updateMe`,
      user
    );
    commit('setUpdatedUser', response.data);
  } catch (err) {
    console.log(err);
  }
}

// CONTROLLER
exports.updateMe = catchAsync(async (req, res, next) => {
  const updatedUser = await User.findByIdAndUpdate(
    req.body.id,
    {
      name: req.body.name,
      email: req.body.email
    },
    { new: true, runValidators: true }
  );
  res.status(204).json({ data: updatedUser });
});

【问题讨论】:

    标签: axios vuex


    【解决方案1】:

    204 是无内容响应代码。

    【讨论】:

      猜你喜欢
      • 2018-03-22
      • 2021-05-03
      • 1970-01-01
      • 2021-05-22
      • 2018-02-16
      • 2020-04-21
      • 1970-01-01
      • 2020-08-20
      • 2021-10-13
      相关资源
      最近更新 更多