nodejs 接收参数,js前端传参方法

nodejs

// 接口:查询检测结果 req.query接收
router.get('/getDetectionResult', (req, res) => {
  console.log(req.query.id);
  const conn = mysql.createConnection(models.mysql)
  const sql = ` select ci.Name,pc.Result  from product p 
 left join productcheckresult pc on pc.ProductId= p.Id 
 left join configurationplan  plan on plan.Id=pc.ConfigurationPlanId
 left join checkitem  ci on ci.Id=plan.CheckItemId  
 where p.Id='${req.query.id}'`
  conn.query(sql, function (err, result) {
    if(err){
      console.log(err)
    }
    if(result){
      jsonWrite(res, result)
    }
  })
  conn.end()
})

前端js

// 接口:查询返回结果  {params:{id:this.imagesDataList.id}} 传参
    getDetectionResult() {
      this.$http
        .get("http://localhost:3000/api/sysuser/getDetectionResult",{params:{id:this.imagesDataList.id}},{
                            emulateJSON:true
                        })
        .then((response) => {
          
          if (response.status == 200) {
            
            this.detectionResult = response.data;
            // console.log(this.detectionResult);
          } else {
            console.log(response);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

 

posted @ 2022-12-27 16:01  seven&night  阅读(436)  评论(0编辑  收藏  举报