+-
Axios调用api,但不返回数据给客户端。

我试图在VueJS应用程序中限制一个页面查看Upload实例,只允许特定Group的成员查看。

然而,我似乎无法检索该组。axios点击api,我可以在终端看到该路由返回数据,但由于某些原因,没有数据到达客户端。

HEre是我的Vue componenet方法。

async getGroupById() {
  console.log('getting group by id: ', this.upload.groups_id)
  let result = await GroupsService.getGroupById({
    id: this.upload.groups_id
  })
  this.uploadGroup = result 
  console.log('group by id result is: ', this.uploadGroup)
  // this.uploadGroup = result.data
  // console.log('group is gotten')
}

这里是我的服务动作

async getGroupById (params) {
    console.log('in service getting group with id: ', params.id)
    let response = await axios.get('groups/' + params.id)
    console.log ('this is the response: ', response.data)
    if (response.status === 200) {
      return response.data;
    }
  }

这里是我的快递路线

router.get('/:id', async (req, res, next) => {
  var id = req.params.id;
  console.log('in groups id is: ', id)
  let results = await Group.query().findById( id ).eager('user');
  console.log('this is the group found: ', results)
  res.json(results);
});

控制台的日志都是通过快速路由发射的,但是在那之后,比如这个。

 console.log ('this is the response: ', response.data)

没有被调用

0
投票

你应该在 axios 调用周围加上 try catch。let response = await axios.get('groups/' + params.id) 线,看看有什么问题。

try {
     let response = await axios.get('groups/' + params.id);
    } catch (err) {
      console.error("Error response:");
      console.error(err.response.data); // ***
      console.error(err.response.status); // ***
      console.error(err.response.headers); // ***
    }