1

问题出在 reactstrap 卡上:https ://reactstrap.github.io/components/card/

使用 Card 等 reactstrap 组件不起作用。

组件:版本 I

import React, { Component } from 'react';
import { Card, Button, CardImg, CardTitle, CardText, CardDeck, CardSubtitle, CardBody } from 'reactstrap';

class MoviesIndex extends Component {

    render() {
        return (
            <CardDeck>
                <Card>
                    <CardImg top width="100%" src="" alt="Movie Poster" />
                </Card>
            </CardDeck>
        );
    }
}

export default MoviesIndex;

输出: *它工作正常,没有任何错误。


但是当我尝试使用 reactstrap 的其余组件时。它在控制台上引发错误。

组件:版本 II

import React, { Component } from 'react';
import { Card, Button, CardImg, CardTitle, CardText, CardDeck, CardSubtitle, CardBody } from 'reactstrap';

class MoviesIndex extends Component {

    render() {
        return (
            <CardDeck>
                <Card>
                    <CardImg top width="100%" src="" alt="Movie Poster" />
                    <CardBody>
                        <CardTitle>Card title</CardTitle>
                        <CardSubtitle>Card subtitle</CardSubtitle>
                        <CardText>This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</CardText>
                        <Button>Button</Button>
                    </CardBody>
                </Card>
            </CardDeck>
        );
    }
}

export default MoviesIndex;

输出: 在此处输入图像描述


包.json

{
  "name": "client",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
    "test:watch": "npm run test -- --watch"
  },
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "jquery": "^2.2.1",
    "jsdom": "^8.1.0",
    "mocha": "^2.4.5",
    "react-addons-test-utils": "^0.14.7",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "axios": "^0.17.1",
    "babel-preset-stage-1": "^6.1.18",
    "lodash": "^3.10.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-transition-group": "^2.2.1",
    "reactstrap": "^4.8.0",
    "redux": "^3.7.2",
    "redux-promise": "^0.5.3"
  }
}

我无法调试此问题。请帮忙!TIA。

4

2 回答 2

4

等组件CardBody在 v4.8.0 中不可用。

升级到最新版本(reactstrap v5.0.0-alpha.4)解决了这个问题!

npm install --save reactstrap@5.0.0-alpha.4

有关详细信息,请参阅我在 reactstrap@github 上创建的问题: https ://github.com/reactstrap/reactstrap/issues/730

于 2017-12-07T14:26:44.930 回答
0

这看起来像一个错字:

renderMovies() {
        return _.map(this.props.movies, movie => {

失踪)

尝试

_.map(this.props.movies, movie) => {

如果那还不行,就把console.log()一切都放在后面,看看它变成了哪里undefined

这种类型的错误通常是由于某些内容未正确导出或由于数据丢失而导致为空/未定义等。

这是我推荐使用 ES Lint 的好机会,因此您可以从被动显示错误中获得 24/7 的额外帮助。如果您不使用它,请检查它。它绝对值得研究和使用。

我不会在这里推荐任何特定的 linting 配置。这超出了本帮助的范围。ES Lint 会用红色下划线对缺失之类的代码错误进行)下划线,这样你就不会遇到这种事情了 :)

于 2017-12-06T17:47:38.923 回答