加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

meteor – const之后的意外令牌

发布时间:2020-12-15 20:15:38 所属栏目:百科 来源:网络整理
导读:当我尝试指定一个常量时,我??在React中收到意外的令牌错误,我似乎无法弄清楚原因. 我的代码非常简单,我几乎完全遵循了react-bootstrap示例here. 我的代码如下: import { Component,PropTypes } from 'react';var rbs = require('react-bootstrap'),Panel =
当我尝试指定一个常量时,我??在React中收到意外的令牌错误,我似乎无法弄清楚原因.

我的代码非常简单,我几乎完全遵循了react-bootstrap示例here.

我的代码如下:

import { Component,PropTypes } from 'react';

var rbs = require('react-bootstrap'),Panel = rbs.Panel;

export default class ResumeSection extends Component {
  constructor(...args) {
    super(...args);
    this.state = {
      open: true
    };
  }

  const title = (
    <h3>Panel title</h3>
  );

  render() {
    return (
      <Panel collapsible expanded={this.state.open}>
        <p>Body</p>
      </Panel>
    );
  }
}

在const之后直接发生错误,并且只是说出了SyntaxError:Unexpected Token

解决方法

你不能像那样在类体中定义一个const;它应该被移动到一个方法中.

render() {
  const title = (
    <h3>Panel title</h3>
  );
  // ...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读