tiefen_space_h5/app/page.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-06-24 22:12:13 +08:00
"use client";
import React,{useRef,useState} from 'react'
import { Tabs, Swiper } from 'antd-mobile'
import { AppstoreOutline,SearchOutline } from 'antd-mobile-icons'
const tabItems = [
{ key: 'commend', title: '推荐' },
{ key: 'follow', title: '关注' },
]
export default function Home() {
const swiperRef = useRef(null)
const [activeIndex, setActiveIndex] = useState(1)
return (
<main className="min-h-screen p-4">
<div className='flex justify-between items-center'>
<Tabs
activeKey={tabItems[activeIndex].key}
onChange={key => {
const index = tabItems.findIndex(item => item.key === key)
setActiveIndex(index)
swiperRef.current?.swipeTo(index)
}}
>
{tabItems.map(item => (
<Tabs.Tab title={item.title} key={item.key} className='text-left'/>
))}
</Tabs>
<AppstoreOutline className='text-lg'/>
</div>
<Swiper
direction='horizontal'
loop
indicator={() => null}
ref={swiperRef}
defaultIndex={activeIndex}
onIndexChange={index => {
setActiveIndex(index)
}}
>
<Swiper.Item>
<div className="">菠萝</div>
</Swiper.Item>
<Swiper.Item>
<div className="">西红柿</div>
</Swiper.Item>
</Swiper>
</main>
)
}