无法读取未定义的“组件”:将material-ui与browserify一起使用 [英] Cannot read 'component' of undefined: Using material-ui with browserify
问题描述
根据Material-ui设置文档中的建议,我正在使用browserify来管理我的依赖项。当我尝试运行代码时,控制台会显示以下消息:
I'm using browserify to manage my dependencies, as suggested on the material-ui setup doc. When I try to run my code, the console gives me this message:
未捕获的TypeError:无法读取未定义的属性 component
,可追溯到 bundle.js:6769
在我的 bundle.js
文件,第6769行是此函数的返回语句:
In my bundle.js
file, line 6769 is the return statement of this function:
getThemeButton: function getThemeButton() {
return this.context.muiTheme.component.button;
},
我在这里想念什么?我对我正在使用的material-ui和material-ui组件都有要求的语句。
What am I missing here? I have require statements for both material-ui and the material-ui components that I am using.
index.js文件的顶部如下所示:
The top of my index.js file looks like this:
var React = require('react');
var injectTapEventPlugin = require('react-tap-event-plugin');
var mui = require('material-ui');
var RaisedButton = mui.RaisedButton;
injectTapEventPlugin();
推荐答案
找到了隐藏在文档!
显然,这是material-ui的必需部分(我不知道为什么他们没有将它作为设置的一部分),但是我需要将该代码段包含在我的渲染类中:
Apparently this is a required part of material-ui (I don't know why they didn't include it as part of the set-up), but I needed to include this snippet in my rendered classes:
childContextTypes: {
muiTheme: React.PropTypes.object
},
getChildContext: function() {
return {
muiTheme: ThemeManager.getCurrentTheme()
};
},
这篇关于无法读取未定义的“组件”:将material-ui与browserify一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!