当前位置:网站首页>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: {
},
}
})
效果如下图:

(完)
边栏推荐
- 【剑指offer】序列化二叉树
- Pytorch view tensor memory size
- 【嵌入式】Cortex M4F DSP库
- Browser thread
- win10系统中的截图,win+prtSc保存位置
- @Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)
- visdom可视化实现与检查介绍
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
- LeetCode:26. 删除有序数组中的重复项
猜你喜欢

Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines

Mongodb installation and basic operation

Alibaba cloud server mining virus solution (practiced)

MongoDB 的安装和基本操作

Roguelike game into crack the hardest hit areas, how to break the bureau?

ESP8266-RTOS物联网开发

Restful API design specification

LeetCode:124. 二叉树中的最大路径和

704 binary search

TCP/IP协议
随机推荐
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
Purpose of computer F1-F12
Problems in loading and saving pytorch trained models
项目连接数据库遇到的问题及解决
Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
win10系统中的截图,win+prtSc保存位置
深度剖析C语言数据在内存中的存储
LeetCode:162. 寻找峰值
Deep anatomy of C language -- C language keywords
JS native implementation shuttle box
UnsupportedOperationException异常
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
vb.net 随窗口改变,缩放控件大小以及保持相对位置
LeetCode:124. 二叉树中的最大路径和
The mysqlbinlog command uses
Charging interface docking tutorial of enterprise and micro service provider platform
Tdengine biweekly selection of community issues | phase III
Shift Operators
Generator parameters incoming parameters
Chrome浏览器的crash问题