Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 请求在axios.get.js上中止_Javascript_Node.js_Reactjs_Axios - Fatal编程技术网

Javascript 请求在axios.get.js上中止

Javascript 请求在axios.get.js上中止,javascript,node.js,reactjs,axios,Javascript,Node.js,Reactjs,Axios,我试图通过令牌从本地存储发出get请求,但它给了我请求中止的错误 这是我的nodeJS代码: //Read app.get('/:username',verify, (req, res) => { console.log('Welcome to roffys server') Todo.find({'username' : req.params.username}) .exec((err, todo) => { if (err) { c

我试图通过令牌从本地存储发出get请求,但它给了我请求中止的错误

这是我的nodeJS代码:

    //Read
app.get('/:username',verify, (req, res) => {
 console.log('Welcome to roffys server')
 Todo.find({'username' : req.params.username})
     .exec((err, todo) => {
      if (err) {
       console.log('Error retrieving todos')
      } else {
       res.json(todo)
      }
     })
})
以下是验证功能:

    const jwt = require('jsonwebtoken')

module.exports = function (req,res,next){
    const token = req.header('Authentication')
    if(!token) return res.status(401).send('Access Denied')

    try {
        const verified = jwt.verify(token, 'secretkey')
         req.user = verified
    }catch (err) {
        res.status(400).send(
            'Invalid token'
        )
        next()
    }
这是我在ReactJS组件上的FE:

   componentDidMount() {
    axios
        .get(`http://localhost:8080/${localStorage.getItem('username')}`,{
            headers : {
                Authentication : localStorage.getItem('token')
            }
        })
        .then((res) => {
            this.setState({todos: res.data})
            this.setPageCount()
        })
        .catch((err) => {
            console.log("err", err);
        });
}

所有方法都不会返回任何内容


componentDidMout () {
  return axios.get(url, config)
            .then (res=> this.setState(myProp: res.data});

......
Back
var verify = require(“./path/to verify”);

    //Read
app.get('/:username',verify, (req, res) => {

return Todo.find({'username' : req.params.username})
     .exec()
      .then(todo=> res.json(todo))
      .catch(console.log);
})


你能告诉我怎么修吗?