我一直在尝试使用react-mounter在Meteor中设置material-ui主题来安装组件。
我遇到了设置问题,然后我扩展了组件,以便我可以使用material-ui网站上的示例设置主题。
我现在收到以下错误消息。
client / components / navbar.jsx:14:4:/client/components/navbar.jsx:缺少 类属性转换。
这是导航栏示例代码
import React from 'react';
import AppBar from 'material-ui/AppBar';
import IconButton from 'material-ui/IconButton';
import Navigationclose from 'material-ui/svg-icons/navigation/close';
import IconMenu from 'material-ui/IconMenu';
import NavigationMoreVert from 'material-ui/svg-icons/navigation/more-vert';
import MenuItem from 'material-ui/MenuItem';
import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
class Navbar extends React.Component {
childContextTypes: {
muiTheme: React.PropTypes.object.isRequired
}
getChildContext() {
return {muiTheme: getMuiTheme(baseTheme)};
}
render() {
return (<AppBar
title="Title"
iconElementLeft={<IconButton><Navigationclose /></IconButton>}
iconElementRight={
<IconMenu
iconButtonElement={
<IconButton><NavigationMoreVert /></IconButton>
}
targetOrigin={{horizontal: 'right', vertical: 'top'}}
anchorOrigin={{horizontal: 'right', vertical: 'top'}}
>
<MenuItem primaryText="Refresh"/>
<MenuItem primaryText="Help"/>
<MenuItem primaryText="Sign out"/>
</IconMenu>
}
/>);
}
}
export default Navbar;
这是router.jsx
import React from 'react';
import {mount} from 'react-mounter';
import {MainLayout} from '/client/layouts/mainLayout.jsx';
import Content from '/client/components/content.jsx';
import Navbar from '/client/components/navbar.jsx';
import Footer from '/client/components/footer.jsx';
FlowRouter.route("/", {
action () {
mount(MainLayout, {
navbar: <Navbar/>,
content: <Content/>,
footer: <Footer/>
});
}
});
答案 0 :(得分:2)
你需要一个巴别变换。 Meteor 1.3.3+通过.babelrc
支持其他插件和预设安装静态转换:
npm install babel-plugin-transform-class-properties
# .babelrc
{
"presets": [
"meteor",
"es2015",
"stage-1"
],
"plugins": [
"transform-class-properties"
]
}
答案 1 :(得分:0)
我把它从扩展类改为React.createClass,它现在可以工作了。
import React from 'react';
import AppBar from 'material-ui/AppBar';
import IconButton from 'material-ui/IconButton';
import Navigationclose from 'material-ui/svg-icons/navigation/close';
import IconMenu from 'material-ui/IconMenu';
import NavigationMoreVert from 'material-ui/svg-icons/navigation/more-vert';
import MenuItem from 'material-ui/MenuItem';
import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
var Navbar = React.createClass({
childContextTypes: {muiTheme: React.PropTypes.object},
getChildContext() {
return {muiTheme: getMuiTheme(baseTheme)};
},
navigate(event, index, item) {
console.log('navigate', item);
FlowRouter.go(item.route);
},
getMenuItems() {
console.log('navigate1');
return [
{ route: '/', text: 'Home' },
{ route: '/table', text: 'Table' }
];
},
render() {
console.log('Render');
return (<AppBar
title="Title"
iconElementLeft={<IconButton><Navigationclose /></IconButton>}
iconElementRight={
<IconMenu
iconButtonElement={
<IconButton><NavigationMoreVert /></IconButton>
}
targetOrigin={{horizontal: 'right', vertical: 'top'}}
anchorOrigin={{horizontal: 'right', vertical: 'top'}}
>
<MenuItem primaryText="Refresh"/>
<MenuItem primaryText="Help"/>
<MenuItem primaryText="Sign out"/>
</IconMenu>
}
/>);
}
});
export default Navbar;