我想加 刷卡器 到我的React Web App,我在使用常规插件时遇到了麻烦,所以我决定使用这个框架来代替。swiper-react 专门为React设计的。
按照入门教程。
Stylesheet
/*react-id-swiper requires Swiper's stylesheet. You can use CDN or use provided stylesheet files (css or scss) from react-id-swiper/lib/styles*/
Provided stylesheet files
// scss
import 'react-id-swiper/lib/styles/scss/swiper.scss';
// css
import 'react-id-swiper/lib/styles/css/swiper.css';
它说我需要导入这些CSS文件 但当我试图在我的Component中导入它们时,在运行时我得到:
./src/component/component/HorizontalEventList.jsx
Module not found: Can't resolve 'react-id-swiper/lib/styles/css/swiper.css' in '/Users/giulioserra/Documents/Siti Web/Hangover/hangover/src/component/component'
没有这些文件,页面上的结果是:
这是页面的代码。
import React, { Component } from "react";
import { Link } from "react-router-dom";
import global from "../../resource/global.json";
import System from "../../System/System";
import Spinner from "../component/Spinner";
import EventMini from "../card/EventMini";
import Swiper from 'react-id-swiper';
export default class HorizontalEventList extends Component {
constructor() {
super();
this.state = {
dataFetched: false,
emptyMessage: "Nulla da visualizzare.",
};
}
componentDidMount() {
//here we check if there is a callback to fetch data from
try {
if (this.state.dataFetched) return;
if (this.props.datasource !== undefined) {
this.setState({ datasource: this.props.datasource, dataFetched: true });
return;
}
if (this.props.dataCallback !== undefined && !this.state.dataFetched) {
this.props.dataCallback().then((events) => {
this.setState({ datasource: events, dataFetched: true });
});
}
} catch (err) {
console.log({ error: err });
this.setState({ datasource: {}, dataFetched: true });
}
}
/**
* Generate a list to display the events
* @author Giulio Serra <[email protected]>
*/
generateEvenList() {
let elements = [];
for (const eventID in this.props.datasource) {
const event = this.props.datasource[eventID];
elements.push(
<li
key={eventID}
style={{
marginLeft: "30px",
marginRight: "30px",
marginBottom: "30px",
}}
>
<EventMini event={{ [eventID]: event }} />
</li>
);
}
return (
<div>
<ul
className="list-group list-group-horizontal"
style={{ listStyle: "none", overflowX: "auto" }}
>
{elements}
</ul>
</div>
);
}
render() {
const params = {
slidesPerView: 3,
spaceBetween: 30,
pagination: {
el: '.swiper-pagination',
clickable: true,
}
}
return (
<Swiper {...params}>
<div>Slide #1</div>
<div>Slide #2</div>
<div>Slide #3</div>
<div>Slide #4</div>
<div>Slide #5</div>
</Swiper>
)
}
我到底做错了什么?谢谢。
它说在 造型 的部分 自述文件.
对于版本<=2.3.2。
你可以直接从
react-id-swiper/lib/styles/
(支持css、scss)css
import 'react-id-swiper/lib/styles/css/swiper.css'
scss
import 'react-id-swiper/lib/styles/scss/swiper.scss'
对于版本>=3.0.0。
你应该直接从
Swiper
支持css、scss和less的包。css
import 'swiper/css/swiper.css'
scss
import 'swiper/swiper.scss'
较少
import 'swiper/swiper.less'
你应该尝试导入v3.0.0,因为那是npm上的当前版本。