assistant-todo-mobile/src/pages/Home/index.js

64 lines
2.1 KiB
JavaScript
Raw Normal View History

2023-01-14 02:09:13 -05:00
import React from 'react'
2023-01-14 02:43:31 -05:00
import { Swiper, Grid } from 'antd-mobile'
2023-01-14 02:09:13 -05:00
import axios from 'axios';
2023-01-14 02:43:31 -05:00
import WidthUseNavigate from '../WidthUseNavigate';
2023-01-14 02:09:13 -05:00
import './index.css'
import ImgZZ from './../../assets/images/nav-1.png'
import ImgHZ from './../../assets/images/nav-2.png'
import ImgDTZF from './../../assets/images/nav-3.png'
import ImgQCZ from './../../assets/images/nav-4.png'
2023-01-14 02:43:31 -05:00
2023-01-14 02:09:13 -05:00
const localCatalog = [
{ "imgSrc": ImgZZ, "title": "整租" ,"path":"/todo"},
{ "imgSrc": ImgHZ, "title": "合租" ,"path":"/todo"},
{ "imgSrc": ImgDTZF, "title": "地图找房" ,"path":"/message"},
{ "imgSrc": ImgQCZ, "title": "去出租" ,"path":"/me"}
]
2023-01-14 02:43:31 -05:00
class HomeInner extends React.Component {
2023-01-14 02:09:13 -05:00
state = {
swipers: []
}
async getSwitpers() {
const res = await axios.get('http://localhost:8080/home/swiper')
console.log('轮播图信息' + res.data.body)
this.setState(
{ swipers: res.data.body }
// ()=>{
// return{swipers:res.data.body}
// }
)
}
componentDidMount() {
this.getSwitpers()
}
renderSwipers() {
return this.state.swipers.map(item => (<Swiper.Item key={item.id}>
<img
src={'http://localhost:8080' + item.imgSrc}
style={{ width: '100%', verticalAlign: 'top' }}
/>
</Swiper.Item>))
}
render() {
return <div className='context'>
<Swiper autoplay loop>{this.renderSwipers()}</Swiper>
<Grid columns={4}>
{
localCatalog.map((item,index) => (
<Grid.Item key={index} onClick={()=>{
console.log("点击跳转")
2023-01-14 02:43:31 -05:00
this.props.to(item.path)}}>
2023-01-14 02:09:13 -05:00
<div ><img src={item.imgSrc} /><h2>{item.title}</h2></div>
</Grid.Item>
))
}
</Grid>
</div>
};
2023-01-14 02:43:31 -05:00
}
// 使用高阶组件包裹当前类组件
const Home = WidthUseNavigate(HomeInner);
// 导出包裹后的类组件
export default Home;