当前位置:网站首页>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: {
},
}
})
效果如下图:
(完)
边栏推荐
- Trying to use is on a network resource that is unavailable
- JVM quick start
- 广州推进儿童友好城市建设,将探索学校周边200米设安全区域
- 被破解毁掉的国产游戏之光
- Navicat premium create MySQL create stored procedure
- swagger设置字段required必填
- C語言雙指針——經典題型
- LeetCode:236. 二叉树的最近公共祖先
- sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
- Philosophical enlightenment from single point to distributed
猜你喜欢
被破解毁掉的国产游戏之光
What is CSRF (Cross Site Request Forgery)?
marathon-envs项目环境配置(强化学习模仿参考动作)
JVM quick start
Restful API design specification
【嵌入式】使用JLINK RTT打印log
Process of obtaining the electronic version of academic qualifications of xuexin.com
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
使用latex导出IEEE文献格式
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
随机推荐
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
egg. JS getting started navigation: installation, use and learning
Tcp/ip protocol
The harm of game unpacking and the importance of resource encryption
JS inheritance method
ESP8266-RTOS物联网开发
How to conduct interface test? What are the precautions? Nanny level interpretation
pytorch查看张量占用内存大小
egg. JS project deployment online server
个人电脑好用必备软件(使用过)
可变长参数
广州推进儿童友好城市建设,将探索学校周边200米设安全区域
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
Screenshot in win10 system, win+prtsc save location
R language uses the principal function of psych package to perform principal component analysis on the specified data set. PCA performs data dimensionality reduction (input as correlation matrix), cus
Indentation of tabs and spaces when writing programs for sublime text
Philosophical enlightenment from single point to distributed
After reading the programmer's story, I can't help covering my chest...
LeetCode:剑指 Offer 42. 连续子数组的最大和
@Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)