当我在 Quagga.onDetected 中调用函数时,显示错误“无法读取未定义的属性 'searchbybarcode'”

问题描述

我正在使用 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,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,{ color: "#00F",linewidth: 2 });
        }

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

      }

    });

  });
}

请告诉我如何在 Quagga.onDetected调用函数

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)