1
我在我加入moment.js忽略eslint錯誤反應的應用,因爲像這樣的外部資源:爲moment.js
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
當我在我的代碼文件中使用moment
其中eslint
啓用然後我得到此eslint錯誤:'moment' is not defined(no-undef)
。
這是我.jsx文件 -
constructor() {
super()
this.state = {
startDate: moment()
}
}
...
我eslintrc.yml
這個樣子的:
extends:
- jquery
- airbnb
parser: babel-eslint
parserOptions:
ecmaVersion: 6
ecmaFeatures:
experimentalObjectRestSpread: true
jsx: true
sourceType: "module"
env:
browser: true
node: true
jquery: true
...
由於您正在全局使用矩形(綁定到窗口對象),因此您可以在模塊中使用window.moment。作爲替代,您可以通過npm安裝時間,並將其用作代碼中的任何其他模塊。 – Hoshts