当前位置:网站首页>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 )
边栏推荐
- LeetCode:39. 组合总和
- Mise en œuvre de la quantification post - formation du bminf
- [embedded] cortex m4f DSP Library
- LeetCode:剑指 Offer 42. 连续子数组的最大和
- Notes 01
- 如何正确截取字符串(例:应用报错信息截取入库操作)
- 在QWidget上实现窗口阻塞
- 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
- 多元聚类分析
- 随手记01
猜你喜欢
[OC-Foundation框架]-<字符串And日期与时间>
Computer graduation design PHP Zhiduo online learning platform
多元聚类分析
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
BN折叠及其量化
vb. Net changes with the window, scales the size of the control and maintains its relative position
Intel Distiller工具包-量化实现3
Advanced Computer Network Review(5)——COPE
BMINF的后训练量化实现
Post training quantification of bminf
随机推荐
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
Selenium+Pytest自动化测试框架实战
What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
[OC-Foundation框架]--<Copy对象复制>
LeetCode:39. 组合总和
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
[embedded] print log using JLINK RTT
Advance Computer Network Review(1)——FatTree
TP-LINK enterprise router PPTP configuration
Esp8266-rtos IOT development
LeetCode:214. Shortest palindrome string
使用标签模板解决用户恶意输入的问题
数学建模2004B题(输电问题)
LeetCode:剑指 Offer 42. 连续子数组的最大和
TP-LINK 企业路由器 PPTP 配置
MongoDB 的安装和基本操作
A convolution substitution of attention mechanism
LeetCode:236. 二叉树的最近公共祖先
LeetCode:673. Number of longest increasing subsequences
在QWidget上实现窗口阻塞