Javascript 无法读取';组件';未定义的类型:使用带有browserify的材质ui
我正在使用browserify来管理我的依赖项,正如material ui设置文档中所建议的那样。当我尝试运行代码时,控制台会显示以下消息:Javascript 无法读取';组件';未定义的类型:使用带有browserify的材质ui,javascript,reactjs,browserify,Javascript,Reactjs,Browserify,我正在使用browserify来管理我的依赖项,正如material ui设置文档中所建议的那样。当我尝试运行代码时,控制台会显示以下消息: 未捕获类型错误:无法读取未定义的的属性“component”,该属性可追溯到bundle.js:6769 在我的bundle.js文件中,第6769行是此函数的返回语句: getThemeButton: function getThemeButton() { return this.context.muiTheme.componen
未捕获类型错误:无法读取未定义的
的属性“component”,该属性可追溯到bundle.js:6769
在我的bundle.js
文件中,第6769行是此函数的返回语句:
getThemeButton: function getThemeButton() {
return this.context.muiTheme.component.button;
},
我错过了什么?对于我正在使用的材质ui和材质ui组件,我都有require语句
我的index.js文件的顶部如下所示:
var React = require('react');
var injectTapEventPlugin = require('react-tap-event-plugin');
var mui = require('material-ui');
var RaisedButton = mui.RaisedButton;
injectTapEventPlugin();
找到了隐藏在地图中的答案 显然,这是material ui的必需部分(我不知道他们为什么不将其作为设置的一部分),但我需要在呈现的类中包含此代码段:
childContextTypes: {
muiTheme: React.PropTypes.object
},
getChildContext: function() {
return {
muiTheme: ThemeManager.getCurrentTheme()
};
},
那里没有足够的代码来查看问题。你为你的组件定义了“contextTypes”吗?我完全没有。现在它工作了:-)