我可以在常量中声明一个方法Meteor onLogout吗?

时间:2017-10-03 04:02:14

标签: reactjs meteor logout accounts

我可以在常量中声明一个方法,我尝试在导航栏中实现onLogout方法,但是我在方法中遇到错误,说'' js [;]期望'或要求以这种方式宣布课程:

  

导出默认类Landing扩展了React.Component

import React from 'react';
import {Link} from 'react-router'
import { Accounts } from 'meteor/accounts-base';

const NavbarLanding = () => {
  onLogout() {
    Meteor.logout();
  };
  return (
    <div className="navbar-landing">
      <nav>
        <div>
          <ul className="ul-landing">
            <img src="/images/fly_paper.svg"></img>
            <li className="navbar-title"><a>Landing</a></li>
 {/* <img border="0" height="40" hspace="0" src="/images/fly_paper.png" width="80" /> */}
 {/* onClick={this.onLogout.bind(this) */}
 {/* btn-primary */}
            <div className="navbar-menu">
              <li><a>acerca</a></li>
              <li><a>portafolio</a></li>
              <li><a>contacto</a></li>

              <button className="btn"onClick={this.onLogout.bind(this)}>Logout</button>
            </div>
          </ul>
        </div>
      </nav>
    </div>
  );
};

export default NavbarLanding;

NavbarLanding.reactProptype = {
  title: React.PropTypes.string.isRequired
};

1 个答案:

答案 0 :(得分:0)

您声明了组件时出错了,它应该是这样的:

export default class NavbarLanding extends React.Component {
  onLogout() {
    Meteor.logout();
  }

  render() {
    return (
      // your html here
    );
  }
};

NavbarLanding.reactProptype = {
  title: React.PropTypes.string.isRequired
};