我正在开发ionic2
项目。我刚刚开始使用 moment.js
但遇到了一个奇怪的问题。
我已通过 npm 安装:npm install moment -S
。
然后我在我的代码中使用了它:
import moment from 'moment'
...
let x = moment()
debugger
在控制台上我遇到了这个有趣的问题:
> x
< Moment {_isAMomentObject: true, _isUTC: false, _pf: {…}, _locale: Locale, _d: Wed Jun 27 2018 12:06:23, …}
> y = moment()
< VM770:1 Uncaught ReferenceError: moment is not defined
at eval (eval at Phase (phase.ts:13), <anonymous>:1:1)
at new Phase (phase.ts:13)
at new Stage (stage.ts:10)
at new HomePage (home.ts:39)
at createClass (core.es5.js:10795)
at createDirectiveInstance (core.es5.js:10621)
at createViewNodes (core.es5.js:11971)
at createRootView (core.es5.js:11876)
at callWithDebugContext (core.es5.js:13007)
at Object.debugCreateRootView [as createRootView] (core.es5.js:12468)
为什么我无法在控制台中使用 moment?
最佳答案
可以像这样从浏览器控制台获取它:
fetch('https://momentjs.com/downloads/moment.min.js')
.then(response => response.text())
.then(text => eval(text))
关于google-chrome - 如何让 chrome devtools 识别 moment.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51058881/