0

我正在使用 quagga 插件表单条形码扫描仪。

当我有结果时,我想在searchbybarcode (barcode){}里面调用函数。Quagga.onDetected

 Quagga.onDetected((res) => {
        console.log('barcode', res.codeResult.code)
 this.searchbybarcode(res.codeResult.code)
      });

当我调用这个函数显示

错误 core.js:6014 错误类型错误:无法读取未定义的属性“searchbybarcode”

  searchbybarcode(barcode) {
    console.log('mybarcode', barcode)
    this.dataservice.GetByBarCode(barcode).then(models => {
      this.PersonDetailsByBarcode = models;
    })
  }

更新

scanbarcode() {
  if (!navigator.mediaDevices || !(typeof navigator.mediaDevices.getUserMedia === 'function')) {
    this.errorMessage = 'getUserMedia is not supported';

    return;
  }
  Quagga.init({
    inputStream: {
      name: "Live",
      type: "LiveStream",
      constraints: {
        width: 480,
        height: 320,
        facingMode: "environment"
      },

    },
    decoder: {
      readers: [
        "code_128_reader",
        "ean_reader",
        "ean_8_reader",
        "code_39_reader",
        "code_39_vin_reader",
        "codabar_reader",
        "upc_reader",
        "upc_e_reader",
        "i2of5_reader"
      ],
    }
  }, function (err) {
    if (err) {
      console.log(err);
      return
    }
    console.log("Initialization finished. Ready to start");
    Quagga.start();
    Quagga.onProcessed(function (result) {
      var drawingCtx = Quagga.canvas.ctx.overlay,
        drawingCanvas = Quagga.canvas.dom.overlay;
      if (result) {
        if (result.boxes) {
          drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")), parseInt(drawingCanvas.getAttribute("height")));
          result.boxes.filter(function (box) {
            return box !== result.box;
          }).forEach(function (box) {
            Quagga.ImageDebug.drawPath(box, { x: 0, y: 1 }, drawingCtx, { color: "green", lineWidth: 2 });
          });
        }

        if (result.box) {
          Quagga.ImageDebug.drawPath(result.box, { x: 0, y: 1 }, drawingCtx, { color: "#00F", lineWidth: 2 });
        }

        if (result.codeResult && result.codeResult.code) {
          Quagga.ImageDebug.drawPath(result.line, { x: 'x', y: 'y' }, drawingCtx, { color: 'red', lineWidth: 3 });
          Quagga.onDetected((res) => {
            console.log('barcode', res.codeResult.code)
          });
        }

      }

    });

  });
}

拜托,你能和我分享一下如何调用里面的函数吗 Quagga.onDetected

4

0 回答 0