我正在使用 browserify 来管理我的依赖项,如 Material-ui 设置文档中的建议。当我尝试运行代码时,控制台会向我显示以下消息:
未捕获的类型错误:无法读取未定义的属性“组件”
,可追溯到bundle.js:6769
在我的 bundle.js
文件中,第 6769 行是该函数的返回语句:
getThemeButton: function getThemeButton() {
return this.context.muiTheme.component.button;
},
我在这里缺少什么?我对我正在使用的material-ui 和material-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();
最佳答案
找到隐藏在 docs 中的答案!
显然这是material-ui的必需部分(我不知道为什么他们不将其作为设置的一部分),但我需要在我的渲染类中包含此代码段:
childContextTypes: {
muiTheme: React.PropTypes.object
},
getChildContext: function() {
return {
muiTheme: ThemeManager.getCurrentTheme()
};
},
关于javascript - 无法读取未定义的 : Using material-ui with browserify 的 'component',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30717886/