当前位置:网站首页>The carousel component of ant design calls prev and next methods in TS (typescript) environment
The carousel component of ant design calls prev and next methods in TS (typescript) environment
2022-07-06 09:03:00 【Frost and snow】
One . Environmental Science
react: “18.1.0”
antd:“^4.20.5” (react edition )
next.js:“12.1.6”
typescript:“4.6.4”
Two . Code
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} hide tab Toggle bar ( Small button ) vertical={true} Moving vertically
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: {
},
}
})
The effect is as follows :

( End )
边栏推荐
- 【shell脚本】——归档文件脚本
- 使用标签模板解决用户恶意输入的问题
- Intel Distiller工具包-量化实现3
- xargs命令的基本用法
- 一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
- 不同的数据驱动代码执行相同的测试场景
- Unsupported operation exception
- LeetCode:34. Find the first and last positions of elements in a sorted array
- vb. Net changes with the window, scales the size of the control and maintains its relative position
- Navicat premium create MySQL create stored procedure
猜你喜欢

Navicat premium create MySQL create stored procedure

ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法

CUDA实现focal_loss

Selenium+Pytest自动化测试框架实战

Alibaba cloud server mining virus solution (practiced)

什么是MySQL?MySql的学习之路是怎样的

Advanced Computer Network Review(3)——BBR

BMINF的后训练量化实现

UML diagram memory skills
![[OC-Foundation框架]-<字符串And日期与时间>](/img/75/e20064fd0066810135771a01f54360.png)
[OC-Foundation框架]-<字符串And日期与时间>
随机推荐
LeetCode:34. Find the first and last positions of elements in a sorted array
[OC]-<UI入门>--常用控件的学习
[embedded] print log using JLINK RTT
Detailed explanation of dynamic planning
Mise en œuvre de la quantification post - formation du bminf
LeetCode:221. 最大正方形
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
What is an R-value reference and what is the difference between it and an l-value?
BMINF的后训练量化实现
Pytest之收集用例规则与运行指定用例
不同的数据驱动代码执行相同的测试场景
[sword finger offer] serialized binary tree
Pytest's collection use case rules and running specified use cases
Different data-driven code executes the same test scenario
Leetcode: Sword finger offer 48 The longest substring without repeated characters
BN folding and its quantification
LeetCode:214. Shortest palindrome string
I-BERT
[OC-Foundation框架]--<Copy对象复制>