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

(完)
边栏推荐
- [embedded] print log using JLINK RTT
- LeetCode:剑指 Offer 04. 二维数组中的查找
- Using C language to complete a simple calculator (function pointer array and callback function)
- LeetCode:剑指 Offer 03. 数组中重复的数字
- What is CSRF (Cross Site Request Forgery)?
- Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
- 项目连接数据库遇到的问题及解决
- JVM quick start
- Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
- TCP/IP协议
猜你喜欢

TP-LINK 企业路由器 PPTP 配置

pytorch训练好的模型在加载和保存过程中的问题

Double pointeur en langage C - - modèle classique

Sublime text using ctrl+b to run another program without closing other runs

ROS compilation calls the third-party dynamic library (xxx.so)

sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题

Tcp/ip protocol

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

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

JVM quick start
随机推荐
C language double pointer -- classic question type
gcc动态库fPIC和fpic编译选项差异介绍
Screenshot in win10 system, win+prtsc save location
TDengine 社区问题双周精选 | 第三期
【剑指offer】序列化二叉树
Unsupported operation exception
ROS compilation calls the third-party dynamic library (xxx.so)
力扣每日一题(二)
704 binary search
Super efficient! The secret of swagger Yapi
Revit 二次开发 HOF 方式调用transaction
JS native implementation shuttle box
Function coritization
Shift Operators
Revit secondary development Hof method calls transaction
pytorch查看张量占用内存大小
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
sublime text中conda环境中plt.show无法弹出显示图片的问题
MYSQL卸载方法与安装方法
同一局域网的手机和电脑相互访问,IIS设置