【问题标题】:How do I pass a parameter from a static async function to another function?如何将参数从静态异步函数传递到另一个函数?
【发布时间】:2019-06-25 09:56:29
【问题描述】:

我需要将一个名为 createIPN 的静态异步函数中的 URL 参数传递给另一个名为 QRCode 的静态异步函数,以生成包含该 URL 的 QRCode 图像。

我还是 Node.js 的新手,所以我不知道可能是什么问题

class ipn{
 static async QRCode (req, res){
  bcrypt.gensalt(10, function(err, salt){
   bcrypt.hash(URL, salt, function (err, hash)){
    var QR= new QRCode({url})
     QR.save(function(err, code){
      if (err) return console.log(err);
       res.render('qr_page', {code})}   
)}
})
}
static async createIPN(req,res){
var URL=req.body;
...
}
}

我看到的错误是“bcrypt.hash(URL, ...) URL is not defined”

【问题讨论】:

    标签: node.js function scope


    【解决方案1】:

    您的URL 变量应该在QRcode 内,或者您应该在调用QRCode 函数时直接传递它

    【讨论】:

    • 所以你是说我应该在二维码的参数中添加URL?类似于:静态异步 QRCode (req, res, URL)
    猜你喜欢
    • 2019-09-26
    • 2018-10-12
    • 2010-11-23
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 2020-09-26
    相关资源
    最近更新 更多