当前位置: 首页 > 知识库问答 >
问题:

未处理的promise拒绝错误:"网络错误"

公冶京
2023-03-14

错误:
未处理的promise拒绝错误:“网络错误”

我的前端vue应用程序正在http://localhost:8080和后端正在http://localhost:8082我正在请求axios从vue文件到后端的get请求。

onSubmit(){
        return axios.get(`http://192.168.43.35:8082/auth/$(this.email)-$(this.password)`).then(function(response){console.log(response)}).catch(function(error){
            throw error;
            console.log(error);
        });

这就是我的终点

app.get('/auth/:email-:password',cors(),(req,res)=>{
  MongoClient.connect(url, function(err, db) {
  if (err) console.log(err);
  var dbo = db.db("leaveautomation");
  dbo.collection("letters").find({email:req.params.email, password:req.params.password},{ projection: { _id: 0, email: 1,} }).toArray(function(err, result) {
  if (err) console.log(err);
  res.send({
    email: result,
    length: result.length
  });
  db.close();
});
  });})

这个错误的原因是什么?

共有1个答案

岳佐
2023-03-14

您是否在服务器端向中间件添加了源标头?

app.use(function (req, res, next) {
    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', '*');

    // Request methods you wish to allow
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', 'Accept,X-Requested-With,Origin,Content-Type');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);

    // Pass to next layer of middleware
    next();
});
 类似资料:
  • 我在react native中的这个简单api调用有问题,我不知道为什么。我在reactJs上做了完全相同的事情,它在浏览器上运行得非常好。 常量FlatListGames=({导航})= [未处理的promise拒绝:错误:网络错误] node\u modules/axios/lib/core/enhanceError。js:24:11错误。toJSON node_modules/axios/l

  • 我试图构建一些代码,但我得到了以下两个错误: (节点:12909)unhandledpromiserejectionwarning:nosuchsessionerror:试图在没有建立连接的情况下运行命令。throwdecodederror(/home/mattheW/node_modules/selenium-webdriver/lib/error.js:550:15)在parseHttpRes

  • 我想在Repl上为我的游戏实现一个基本的排行榜。它,所以我创建了一个节点。js后端。这是我在后端的配置: 但是每当我尝试发布时,我都会得到以下错误: (节点:344)未处理的PromisejectionWarning:TypeError:无法读取null的属性“push” (节点:344)UnhandledPromiseRejtionWarning:未处理的promise拒绝。这个错误要么是由于抛

  • 未处理的Promise拒绝:模板分析错误:分析器错误:中的[let option of questionForm.controls.Options.controls;index as j]中的第1列出现意外标记letMultiplechoiceComponent@0:126(“表格”

  • 问题内容: 当我使用Node运行此代码时,它会在控制台中引发错误(甚至首先显示文本)。 但是,当我将方法链接到方法时,错误消失了: 难道第一个代码不应该处理拒绝吗? 我还尝试了Chrome中的第一个代码,当我在新标签页(或google.com)中打开检查器时,该代码就可以使用。如果我在其他任何页面中,则会引发异常。有什么解释吗?这对我来说真的很奇怪! 问题答案: 为了被视为已处理,被拒绝的诺言应与

  • 当我运行部署我的应用程序的命令时,我发现以下错误 (节点: 6292)UnhandledPromiseRejtionWarning: UnHandledPromiseRejtionWarning: UnHandledPromiseRejtionWarning: UnHandledPromiseRejtionWarning: UnHandledPromiseRejtionWarning: UnHan