当前位置:网站首页>ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
2022-07-06 08:50:00 【霜雪遥】
一. 环境
react: “18.1.0”
antd:“^4.20.5” (react版)
next.js:“12.1.6”
typescript:“4.6.4”
二. 代码
import type {
NextPage, GetServerSideProps, InferGetServerSidePropsType } from 'next'
import styles from '../styles/Home.module.scss'
import cn from 'classnames'
import {
Store } from '@/store/store'
import {
createRef } from 'react'
import {
Carousel, Button } from 'antd'
import type {
CarouselRef } from 'antd/lib/carousel'
interface IProps {
}
const contentStyle: React.CSSProperties = {
height: '160px',
color: '#fff',
lineHeight: '160px',
textAlign: 'center',
background: '#364d79',
}
const Home: NextPage<InferGetServerSidePropsType<typeof getServerSideProps>> = ({
}) => {
const carRef = createRef<CarouselRef>()
const next = () => {
console.log('next')
carRef.current?.next()
}
const prev = () => {
console.log(carRef)
console.log('prev')
carRef.current?.prev()
}
// dots={false} 隐藏tab切换栏(小按钮) vertical={true} 垂直方向移动
return (
<div className={
cn(styles['home-page'])}>
<Carousel dots={
false} ref={
carRef} vertical={
true}>
<div>
<div style={
contentStyle}>1</div>
</div>
<div>
<div style={
contentStyle}>2</div>
</div>
<div>
<div style={
contentStyle}>3</div>
</div>
<div>
<div style={
contentStyle}>4</div>
</div>
</Carousel>
<Button onClick={
next}>next</Button>
<Button onClick={
prev}>prev</Button>
</div>
)
}
export default Home
export const getServerSideProps: GetServerSideProps<IProps> = Store.getServerSideProps((store) => async ({
req }) => {
return {
props: {
},
}
})
效果如下图:

(完)
边栏推荐
- Compétences en mémoire des graphiques UML
- JS pure function
- 同一局域网的手机和电脑相互访问,IIS设置
- ESP8266-RTOS物联网开发
- Image, CV2 read the conversion and size resize change of numpy array of pictures
- 目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
- Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC
- How to effectively conduct automated testing?
- Alibaba cloud server mining virus solution (practiced)
- 如何有效地进行自动化测试?
猜你喜欢

被破解毁掉的国产游戏之光

ESP8266-RTOS物联网开发

TP-LINK enterprise router PPTP configuration

sublime text中conda环境中plt.show无法弹出显示图片的问题

Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges

Crash problem of Chrome browser

Alibaba cloud server mining virus solution (practiced)

Generator parameters incoming parameters

软件卸载时遇到trying to use is on a network resource that is unavailable
![[embedded] print log using JLINK RTT](/img/22/c37f6e0f3fb76bab48a9a5a3bb3fe5.png)
[embedded] print log using JLINK RTT
随机推荐
Unsupported operation exception
TDengine 社区问题双周精选 | 第三期
个人电脑好用必备软件(使用过)
Restful API design specification
LeetCode:387. 字符串中的第一个唯一字符
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
Esp8266-rtos IOT development
Trying to use is on a network resource that is unavailable
Screenshot in win10 system, win+prtsc save location
704 binary search
Bitwise logical operator
有效提高软件产品质量,就找第三方软件测评机构
egg. JS getting started navigation: installation, use and learning
swagger设置字段required必填
Chrome浏览器的crash问题
Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
优秀的软件测试人员,都具备这些能力
如何进行接口测试测?有哪些注意事项?保姆级解读
On the inverse order problem of 01 knapsack problem in one-dimensional state
Detailed explanation of dynamic planning