Reactstrap Card 组件抛出错误
Reactstrap Card component throws error
问题出在 reactstrap 卡上:https://reactstrap.github.io/components/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;
输出:
package.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.
这看起来像是打字错误:
renderMovies() {
return _.map(this.props.movies, movie => {
失踪)
尝试
_.map(this.props.movies, movie) => {
如果不行,把 console.log()
放在所有内容之后,看看它变成 undefined
.
此类错误通常是由于某些内容未正确导出或某些内容 null/undefined 由于数据丢失等原因造成的。
这是我推荐使用 ES Lint 的好机会,因此您可以从被动显示错误中获得 24/7 全天候的额外帮助。如果您不使用它,请检查一下。绝对值得研究和使用。
我不会在这里推荐任何特定的 linting 配置。这超出了本帮助的范围。 ES Lint 会用红色下划线来强调代码错误,例如缺少 )
,所以你会少遇到这种事情:)
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
问题出在 reactstrap 卡上:https://reactstrap.github.io/components/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;
输出:
package.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.
这看起来像是打字错误:
renderMovies() {
return _.map(this.props.movies, movie => {
失踪)
尝试
_.map(this.props.movies, movie) => {
如果不行,把 console.log()
放在所有内容之后,看看它变成 undefined
.
此类错误通常是由于某些内容未正确导出或某些内容 null/undefined 由于数据丢失等原因造成的。
这是我推荐使用 ES Lint 的好机会,因此您可以从被动显示错误中获得 24/7 全天候的额外帮助。如果您不使用它,请检查一下。绝对值得研究和使用。
我不会在这里推荐任何特定的 linting 配置。这超出了本帮助的范围。 ES Lint 会用红色下划线来强调代码错误,例如缺少 )
,所以你会少遇到这种事情:)
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