当前位置:网站首页>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 )
边栏推荐
- ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
- Improved deep embedded clustering with local structure preservation (Idec)
- 使用标签模板解决用户恶意输入的问题
- Selenium+Pytest自动化测试框架实战(下)
- LeetCode41——First Missing Positive——hashing in place & swap
- LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
- Simple use of promise in uniapp
- Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
- What is MySQL? What is the learning path of MySQL
- opencv+dlib实现给蒙娜丽莎“配”眼镜
猜你喜欢
[OC-Foundation框架]---【集合数组】
Different data-driven code executes the same test scenario
Mise en œuvre de la quantification post - formation du bminf
[OC]-<UI入门>--常用控件的学习
[OC foundation framework] - string and date and time >
Nacos 的安装与服务的注册
Problems encountered in connecting the database of the project and their solutions
Intel Distiller工具包-量化实现2
一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
随机推荐
Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
An article takes you to understand the working principle of selenium in detail
LeetCode:劍指 Offer 42. 連續子數組的最大和
LeetCode:236. The nearest common ancestor of binary tree
UML diagram memory skills
I-BERT
LeetCode:41. 缺失的第一个正数
Simclr: comparative learning in NLP
Using label template to solve the problem of malicious input by users
CUDA implementation of self defined convolution attention operator
Mise en œuvre de la quantification post - formation du bminf
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
Implement window blocking on QWidget
Computer graduation design PHP Zhiduo online learning platform
BN折叠及其量化
LeetCode:162. 寻找峰值
Problems encountered in connecting the database of the project and their solutions
Niuke winter vacation training 6 maze 2
[MySQL] multi table query
What is an R-value reference and what is the difference between it and an l-value?