当前位置:网站首页>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: {
},
}
})
效果如下图:
(完)
边栏推荐
- torch建立的网络模型使用torchviz显示
- 如何有效地进行自动化测试?
- The harm of game unpacking and the importance of resource encryption
- Deep anatomy of C language -- C language keywords
- TDengine 社区问题双周精选 | 第三期
- @JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
- 使用latex导出IEEE文献格式
- Using C language to complete a simple calculator (function pointer array and callback function)
- Purpose of computer F1-F12
- TP-LINK 企业路由器 PPTP 配置
猜你喜欢
After reading the programmer's story, I can't help covering my chest...
软件卸载时遇到trying to use is on a network resource that is unavailable
Process of obtaining the electronic version of academic qualifications of xuexin.com
LeetCode:124. 二叉树中的最大路径和
【剑指offer】序列化二叉树
Light of domestic games destroyed by cracking
PC easy to use essential software (used)
sublime text的编写程序时的Tab和空格缩进问题
ROS compilation calls the third-party dynamic library (xxx.so)
使用latex导出IEEE文献格式
随机推荐
POI add write excel file
Visual implementation and inspection of visdom
egg. JS project deployment online server
vb.net 随窗口改变,缩放控件大小以及保持相对位置
Computer graduation design PHP Zhiduo online learning platform
Purpose of computer F1-F12
有效提高软件产品质量,就找第三方软件测评机构
Warning in install. packages : package ‘RGtk2’ is not available for this version of R
LeetCode:剑指 Offer 04. 二维数组中的查找
LeetCode:剑指 Offer 03. 数组中重复的数字
Navicat premium create MySQL create stored procedure
poi追加写EXCEL文件
如何有效地进行自动化测试?
swagger设置字段required必填
Esp8266-rtos IOT development
Problems in loading and saving pytorch trained models
@Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)
egg. JS getting started navigation: installation, use and learning
LeetCode:836. 矩形重叠
LeetCode:394. 字符串解码