我正在测试视差组件的功能。我首先将react-parallax添加到项目中:
npm install react-parallax --save
从那里,我创建了一个简单的react组件:
import React, { Component } from 'react';
import { withStyles } from '@material-ui/core';
import {Parallax} from 'react-parallax';
const styles = theme => ({
foodImage:'http://glutenfreedelivers.com/template/images/white/glutenfree4.jpg'
});
class ParallaxTest extends Component {
render(){
const {classes} = this.props;
return(
<div>
<Parallax bgImage={classes.foodImage}>
<div style= {{ height:500 }}></div>
</Parallax>
</div>
);
}
}
export default withStyles(styles)(ParallaxTest);
这很简单,但是当我构建它时,我想看到的图像没有显示出来,但是有空白。当我滚动查看我的react-parallax的导入时,会收到以下弹出消息:
Could not find a declaration file for module 'react-parallax'. 'c:/Users/dev/git/project/project/node_modules/react-parallax/dist/index.js' implicitly has an 'any' type.
Try `npm install @types/react-parallax` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-parallax';`
我已经检查了我的node-modules,看起来好像那里有react-parallax的index.js。我已经看到了很多解决方案,其中包括编辑tsconfig.json文件,但是由于我确定自己没有使用打字稿,因此我看不出有什么帮助。无论如何,我希望看到一些有益的答复。预先感谢!