Skip to content

Commit

Permalink
fix: antd 轮播组件滑动报错,更换为 react-slick 轮播组件
Browse files Browse the repository at this point in the history
Carousel throwing error - "Unable to preventDefault inside passive event
listener invocation" issue 链接:ant-design/ant-design#27927
  • Loading branch information
nineSean committed Apr 28, 2021
1 parent 1ca27a0 commit 7901315
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
"react-dom": "^17.0.1",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-slick": "^0.28.1",
"react-transition-group": "^4.4.1",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-promise": "^0.6.0",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"slick-carousel": "^1.8.1"
},
"devDependencies": {
"@babel/core": "^7.12.17",
Expand All @@ -41,6 +43,7 @@
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@types/eslint": "^7.2.6",
"@types/react-slick": "^0.23.4",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"autoprefixer": "^10.2.4",
Expand Down
13 changes: 11 additions & 2 deletions src/components/Slide/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Carousel} from "antd"
import Carousel from "react-slick"
import React, {FC, useEffect} from "react"
import {ISlide} from "@/typings/slide"
import "slick-carousel/slick/slick.css"
import "slick-carousel/slick/slick-theme.css"

interface Props {
className?: string
Expand All @@ -12,8 +14,15 @@ const Slide: FC<Props> = (props: Props) => {
useEffect(() => {
!props.slides.length && props.getSlides()
}, [])
const settings = {
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1
};
return (
<Carousel autoplay className={props.className}>
<Carousel {...settings} className={props.className}>
{
props.slides.map((slide, idx) => <img
src={slide.url}
Expand Down
3 changes: 3 additions & 0 deletions src/routes/Home/index.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
height: 320px;
}
}
.slick-dots {
bottom: 25px;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const path = require('path')
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
mode: isProd ? 'production' : 'development',
devtool: isProd ? 'source-map' : false,
// devtool: 'source-map',
// devtool: isProd ? 'source-map' : false,
devtool: 'source-map',
entry: './src/index.tsx',
output: {
path: path.join(__dirname, 'dist'),
Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = {
'less-loader'
]
}, {
test: /\.(jpg|jpeg|png|gif|svg)$/,
test: /\.(jpg|jpeg|png|gif|svg|eot|ttf|woff|woff2)$/,
type: 'asset'
}
],
Expand Down
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,13 @@
"@types/history" "*"
"@types/react" "*"

"@types/react-slick@^0.23.4":
version "0.23.4"
resolved "https://registry.npm.taobao.org/@types/react-slick/download/@types/react-slick-0.23.4.tgz#c97e2a9e7e3d1933c68593b8e82752fab1e8ce53"
integrity sha1-yX4qnn49GTPGhZO46CdS+rHozlM=
dependencies:
"@types/react" "*"

"@types/react-transition-group@^4.4.0":
version "4.4.0"
resolved "https://registry.npm.taobao.org/@types/react-transition-group/download/@types/react-transition-group-4.4.0.tgz?cache=0&sync_timestamp=1613384573492&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Freact-transition-group%2Fdownload%2F%40types%2Freact-transition-group-4.4.0.tgz"
Expand Down Expand Up @@ -3012,6 +3019,11 @@ enhanced-resolve@^5.7.0:
graceful-fs "^4.2.4"
tapable "^2.2.0"

enquire.js@^2.1.6:
version "2.1.6"
resolved "https://registry.npm.taobao.org/enquire.js/download/enquire.js-2.1.6.tgz#3e8780c9b8b835084c3f60e166dbc3c2a3c89814"
integrity sha1-PoeAybi4NQhMP2DhZtvDwqPImBQ=

enquirer@^2.3.5, enquirer@^2.3.6:
version "2.3.6"
resolved "https://registry.npm.taobao.org/enquirer/download/enquirer-2.3.6.tgz"
Expand Down Expand Up @@ -4910,6 +4922,11 @@ lodash-es@^4.2.1:
resolved "https://registry.npm.taobao.org/lodash-es/download/lodash-es-4.17.20.tgz?cache=0&sync_timestamp=1608444851021&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flodash-es%2Fdownload%2Flodash-es-4.17.20.tgz"
integrity sha1-KfYzLu/GDoSfhpwmS8cRJq1h6Pc=

lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.nlark.com/lodash.debounce/download/lodash.debounce-4.0.8.tgz?cache=0&sync_timestamp=1618847031591&other_urls=https%3A%2F%2Fregistry.nlark.com%2Flodash.debounce%2Fdownload%2Flodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=

lodash.ismatch@^4.4.0:
version "4.4.0"
resolved "https://registry.npm.taobao.org/lodash.ismatch/download/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
Expand Down Expand Up @@ -6459,6 +6476,17 @@ react-router@5.2.0:
tiny-invariant "^1.0.2"
tiny-warning "^1.0.0"

react-slick@^0.28.1:
version "0.28.1"
resolved "https://registry.npm.taobao.org/react-slick/download/react-slick-0.28.1.tgz#12c18d991b59432df9c3757ba540a227b3fb85b9"
integrity sha1-EsGNmRtZQy35w3V7pUCiJ7P7hbk=
dependencies:
classnames "^2.2.5"
enquire.js "^2.1.6"
json2mq "^0.2.0"
lodash.debounce "^4.0.8"
resize-observer-polyfill "^1.5.0"

react-transition-group@^4.4.1:
version "4.4.1"
resolved "https://registry.npm.taobao.org/react-transition-group/download/react-transition-group-4.4.1.tgz"
Expand Down Expand Up @@ -7156,6 +7184,11 @@ slice-ansi@^4.0.0:
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"

slick-carousel@^1.8.1:
version "1.8.1"
resolved "https://registry.npm.taobao.org/slick-carousel/download/slick-carousel-1.8.1.tgz#a4bfb29014887bb66ce528b90bd0cda262cc8f8d"
integrity sha1-pL+ykBSIe7Zs5Si5C9DNomLMj40=

snapdragon-node@^2.0.1:
version "2.1.1"
resolved "https://registry.npm.taobao.org/snapdragon-node/download/snapdragon-node-2.1.1.tgz"
Expand Down

0 comments on commit 7901315

Please sign in to comment.