ecmascript-6 - 用于 Polymer 3x 的 Web 组件的 Quagga JS
问题描述
创建自定义组件后,在聚合物 1.0 中也是如此。聚合物 3.x 组件出现问题。我遇到错误。我尝试使用抛出不同错误的 npm 包管理器,所以我是用户 Quagga.min.js 并直接从我面临以下问题的聚合物组件导入相同的
未捕获的语法错误:请求的模块“/quagga.min.js”不提供名为“默认”的导出
import '@polymer/paper-input/paper-input.js';
import '@polymer/paper-button/paper-button.js';
import '@polymer/iron-image/iron-image.js';
import '@polymer/iron-input/iron-input.js';
import '@polymer/iron-ajax/iron-ajax.js';
import '@polymer/app-storage/app-localstorage/app-localstorage-document.js';
import { ERAppServices } from '../service/er-appservices';
import { PolymerElement, html } from '@polymer/polymer';
import '@polymer/iron-flex-layout/iron-flex-layout-classes.js';
import {
mixinBehaviors
} from '@polymer/polymer/lib/legacy/class.js';
import { ERPolymerElement } from 'er-polymer/elements/er-polymer-element.js';
import Quagga from '/quagga.min.js';
class BarcodeScanner extends ERPolymerElement{
static get template() {
return html`
<style include="er-theme">
:host {
display: block;
padding: 10px;
}
video {
position: absolute;
width: 100%;
height: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
<template>
<div id="interactive" class="viewport"></div>
</template>
`;
}
ready() {
super.ready();
ERAppServices.ERLoaders.stopSplash();
}
static get properties() {
return {
result: {
type: Object,
notify: true,
readOnly: true,
value: null
},
code: {
type: String,
notify: true,
reflectToAttribute: true,
readOnly: true,
value: ''
},
active: {
type: Boolean,
value: true,
notify: true,
reflectToAttribute: true
}
}
}
attached() {
this._isReady = false;
var _this = this;
Quagga.init({
inputStream : {
name : "Live",
type : "LiveStream"
},
decoder : {
readers : ["ean_reader"]
}
}, function(err) {
_this.querySelector('video').className += ' barcode-scanner';
if (err) {
console.log(err);
return;
}
if (_this.active) {
_this._isReady = true;
Quagga.start();
}
});
Quagga.onDetected(function(result) {
if (_this.active) {
_this._setResult(result);
_this._setCode(result.codeResult.code);
console.log("=======================Result",result.codeResult)
_this.fire('recognize', {code: result.codeResult.code, result: result});
}
});
}
suspend() {
Quagga.stop();
}
resume() {
Quagga.start();
}
}
window.customElements.define('barcode-scanner', BarcodeScanner);
解决方案
您正在尝试从不导出 Quagga 的脚本中导入它。
通过 NPM 安装 Quagga,然后将路径更改为“quagga”,这将解决您的问题。
编辑。实际上,我也使用 Polymer 遇到了这个问题。我最终只是在我的 index.html 上添加了通过脚本标记作为解决方法。我认为这是聚合物服务的限制。没有时间通过 ES6 导入使其工作。
推荐阅读
- javascript - 登录后重定向不正确 - Spring Boot
- c++ - 查找数组中哪一行的平均温度最高
- javascript - 如何让我的文本出现在我的滑块顶部?
- amazon-web-services - AWS chmod 400 pem:没有这样的文件或目录问题
- javascript - 一旦屏幕通过特定点或 jsx 标签,如何获取滚动事件?
- c++ - C ++如何生成-32到32或-64到64之间的随机数并且不包括零值?
- javascript - 图像在 jQuery 中没有按顺序褪色?
- javascript - 在 JavaScript 中验证表单
- scala - 如何在 Spark Dataframe 上有效地执行此列操作?
- javascript - Javascript:如何使多个 div 从左侧滑动