2
在Meteor中,如果我在反应组件和console.log中输入nod这样的npm,在以下位置输入“lodash”,它总是会在组件中定义为undefined。同样的事情也发生在一瞬间。我在我的智慧结束,因为从文档说什么我认为这是可能的。这是可能的,如果有的话,我在这里错过了什么?任何帮助深表感谢。在客户端导入npm模块React组件
import React from 'react'
import lodash from 'lodash'
console.log(lodash) // lodash is found just fine
export default class SomeComponent extends React.Component {
constructor(props) {
super(props)
this.someFunction = this.someFunction.bind(this)
}
someFunction() {
console.log(lodash) // Throws error that lodash is undefined.
}
}
之所以如此,是离奇。如果你在一些函数中执行调试器,你能够访问lodash吗? – sturoid
将someFunction改为:'console.log(JSON.stringify(lodash.partition([1,2,3,4],n => n%2)))'产生日志:'[[1,3], [2,4]]' – JeremyK
如果你想要在控制台上使用lodash,你可能需要:在控制台上试试'var lodash = require('lodash')' – JeremyK