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

(完)
边栏推荐
猜你喜欢

Cesium draw points, lines, and faces

JS inheritance method

可变长参数
![[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born](/img/70/d275009134fcbf9ae984c0f278659e.jpg)
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born

Delay initialization and sealing classes

Crash problem of Chrome browser

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

Process of obtaining the electronic version of academic qualifications of xuexin.com

Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures

Light of domestic games destroyed by cracking
随机推荐
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
LeetCode:498. 对角线遍历
LeetCode:387. 字符串中的第一个唯一字符
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
查看局域网中电脑设备
R language ggplot2 visualization, custom ggplot2 visualization image legend background color of legend
Unsupported operation exception
LeetCode:162. 寻找峰值
Navicat premium create MySQL create stored procedure
Alibaba cloud server mining virus solution (practiced)
Deep analysis of C language pointer
Excellent software testers have these abilities
Using C language to complete a simple calculator (function pointer array and callback function)
Screenshot in win10 system, win+prtsc save location
Charging interface docking tutorial of enterprise and micro service provider platform
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
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 changes with the window, scales the size of the control and maintains its relative position
C language double pointer -- classic question type
企微服务商平台收费接口对接教程