当前位置:网站首页>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: {
},
}
})
效果如下图:
(完)
边栏推荐
- egg. JS directory structure
- CSP first week of question brushing
- 使用latex导出IEEE文献格式
- LeetCode:剑指 Offer 04. 二维数组中的查找
- [today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
- LeetCode:394. 字符串解码
- LeetCode:221. 最大正方形
- TP-LINK enterprise router PPTP configuration
- 【嵌入式】Cortex M4F DSP库
- ESP8266-RTOS物联网开发
猜你喜欢
Delay initialization and sealing classes
Computer graduation design PHP Zhiduo online learning platform
Swagger setting field required is mandatory
Light of domestic games destroyed by cracking
opencv+dlib实现给蒙娜丽莎“配”眼镜
[embedded] print log using JLINK RTT
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
LeetCode:498. 对角线遍历
JVM quick start
win10系统中的截图,win+prtSc保存位置
随机推荐
To effectively improve the quality of software products, find a third-party software evaluation organization
Detailed explanation of dynamic planning
Philosophical enlightenment from single point to distributed
UnsupportedOperationException异常
Computer cleaning, deleted system files
有效提高软件产品质量,就找第三方软件测评机构
C语言深度解剖——C语言关键字
LeetCode:498. 对角线遍历
LeetCode:剑指 Offer 03. 数组中重复的数字
egg. JS project deployment online server
Browser thread
Revit secondary development Hof method calls transaction
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
同一局域网的手机和电脑相互访问,IIS设置
Charging interface docking tutorial of enterprise and micro service provider platform
MongoDB 的安装和基本操作
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
egg. JS directory structure
Mobile phones and computers on the same LAN access each other, IIS settings
How to effectively conduct automated testing?