当前位置:网站首页>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: {
},
}
})
效果如下图:
(完)
边栏推荐
- Warning in install. packages : package ‘RGtk2’ is not available for this version of R
- LeetCode:26. 删除有序数组中的重复项
- POI add write excel file
- Deep analysis of C language data storage in memory
- LeetCode:236. 二叉树的最近公共祖先
- Sublime text using ctrl+b to run another program without closing other runs
- 如何进行接口测试测?有哪些注意事项?保姆级解读
- 如何有效地进行自动化测试?
- [today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
- TCP/IP协议
猜你喜欢
角色动画(Character Animation)的现状与趋势
Generator parameters incoming parameters
Nacos 的安装与服务的注册
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
Charging interface docking tutorial of enterprise and micro service provider platform
JS inheritance method
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
JVM quick start
Compétences en mémoire des graphiques UML
pytorch训练好的模型在加载和保存过程中的问题
随机推荐
CSP first week of question brushing
可变长参数
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
ESP8266-RTOS物联网开发
Niuke winter vacation training 6 maze 2
被破解毁掉的国产游戏之光
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
Super efficient! The secret of swagger Yapi
【剑指offer】序列化二叉树
【嵌入式】使用JLINK RTT打印log
Deep anatomy of C language -- C language keywords
LeetCode:673. 最长递增子序列的个数
LeetCode:162. 寻找峰值
R language ggplot2 visualization, custom ggplot2 visualization image legend background color of legend
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
Mobile phones and computers on the same LAN access each other, IIS settings
JS pure function
Philosophical enlightenment from single point to distributed
@Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)