我收到此错误:


  ./src/components/Playing.jsx
    第15行:“ aaa”未定义为no-undef


在我的Playing.jsx中:

import React, { Component } from 'react'

console.log(aaa);


从我的Token.jsx

import { connect } from 'react-redux'
imports { Playing } from '../components/Playing'

const mapStateToProps = state => ({
  aaa: "asdf"
})

export default connect(mapStateToProps)(Playing)

最佳答案

您将无法仅在文件中的任何地方console.log();它必须在Playing组件的某些功能之内;而且也只能通过props使用,例如

class Playing extends React.Component {
  componentDidMount() {
    console.log(this.props.aaa);
  }

  render() {
    return <span>Playing</span>;
  }
}

08-07 08:46