好客租房123-租房数据渲染

简介: 好客租房123-租房数据渲染
import React from 'react'
import axios from 'axios'
//留白
import { Carousel, Flex,Grid} from 'antd-mobile'
import Nav1 from '../../assets/images/nav-1.png'
import Nav2 from '../../assets/images/nav-2.png'
import Nav3 from '../../assets/images/nav-3.png'
import Nav4 from '../../assets/images/nav-4.png'
import Body1 from '../../assets/images/1.png'
import Body2 from '../../assets/images/2.png'
import Body3 from '../../assets/images/3.png'
import Body4 from '../../assets/images/4.png'
//导入样式
import './index.scss'
const navs = [
  {
    id: 1,
    img: Nav1,
    title: '整租',
    path: '/home/list',
  },
  {
    id: 2,
    img: Nav2,
    title: '合租',
    path: '/home/list',
  },
  {
    id: 3,
    img: Nav3,
    title: '地图找房',
    path: '/home/list',
  },
  {
    id: 4,
    img: Nav4,
    title: '去出租',
    path: '/home/list',
  },
]
const data = Array.from(new Array(4)).map((_val, i) => ({
    icon: `Body${i+1}`,
    text: `name${i}`,
  }));
// 轮播图不会自动播放  数据返回过来的时候高度不够 数据加载前后数据的问题
class Index extends React.Component {
  state = {
    data: ['1', '2', '3'],
    imgHeight: 212,
    isSwiperLoding: false,
    groups: [],
        swiper:[]
  }
  componentDidMount() {
    // simulate img loading
    this.getGroups()
        this.getSwipers()
    setTimeout(() => {
      this.setState({
        data: [
          'AiyWuByWklrrUDlFignR',
          'TekJlZRVCjLFexlOCuWn',
          'IJOtIlfsYdTyaDTRVrLI',
        ],
        isSwiperLoding: true,
      })
    }, 100)
  }
  async getSwipers() {
    const res = await axios.get('http://localhost:8080/home/swiper')
    console.log('轮播如数据为:', res)
      this.setState({
          swiper:res.data.body
      })
  }
  async getGroups() {
    const res = await axios.get('http://localhost:8080/home/groups', {
      params: {
        area: 'AREA%7C88cff55c-aaa4-e2e0',
      },
    })
    console.log('轮播如数据为:', res)
    this.setState({
      groups: res.data.body,
    })
  }
  //渲染轮播图的方法
  renderSwipers() {
    return this.state.swiper.map((val) => (
      <a
        key={val.id}
        href="http://www.alipay.com"
        style={{
          display: 'inline-block',
          width: '100%',
          height: this.state.imgHeight,
        }}
      >
        <img
          src={`http://localhost:8080${val.imgSrc}`}
          alt=""
          style={{ width: '100%', verticalAlign: 'top' }}
          onLoad={() => {
            // fire window resize event to change height
            window.dispatchEvent(new Event('resize'))
            this.setState({ imgHeight: 'auto' })
          }}
        />
    ))
  }
  //渲染导航菜单
  renderNavs() {
    return navs.map((item) => (
        key={item.id}
        onClick={() => {
          this.props.history.push(item.path)
        }}
      >
        好客租房123-租房数据渲染_ios
{item.title}
    ))
  }
  render() {
    return (
      //留白 WingBlank
          {this.state.isSwiperLoding === true ? (
              //自动播放
              autoplay={true}
              infinite
              //   beforeChange={(from, to) => console.log(`slide from ${from} to ${to}`)}
              //   afterChange={index => console.log('slide to', index)}
            >
              {this.renderSwipers()}
          ) : (
            ''
          )}
                square={false}
                 className="nav">{this.renderNavs()}
                {/* 租房小组 */}
                            租房小组:更多
                        data={this.state.groups}
                         renderItem={(item)=>(
                                        {item.title}
                                    {item.desc}
                                好客租房123-租房数据渲染_perl_02http://localhost:8080${item.imgSrc}`}/>
                            </Flex>
                        )}  activeStyle={false} />
                </div>
      </div>
    )
  }
}
export default Index

运行结果

图片.png

相关文章
|
安全 API 网络安全
OpenStack的 网络服务(Neutron)
【8月更文挑战第23天】
947 10
|
Web App开发 JavaScript
学习VUE之正则表达式全集整理
学习VUE之正则表达式全集整理
221 0
|
API 开发者
提供一份 1688 商品详情接口的错误码及解决方法
本文介绍了 1688 商品详情接口常见的错误码及其解决方法,包括 401(未授权)、403(禁止访问)、404(未找到)、429(请求过多)和 500/502/504(服务器错误),帮助开发者快速定位并解决问题。
|
Java 测试技术 数据安全/隐私保护
Spring Boot | 一种优雅的参数校验方案(个人总结)
一种优雅的参数校验方案(个人总结)
1609 1
Spring Boot | 一种优雅的参数校验方案(个人总结)
|
JavaScript 前端开发
最万能的登录、注册页。带输入数据的验证。邮箱的正则表达式、正则表达式验证输入的数据
这篇文章提供了一个带有输入数据验证功能的万能登录和注册页面的HTML和JavaScript代码示例,包括正则表达式验证邮箱和用户输入数据。
如何在 Angular 路由中使用路由守卫
如何在 Angular 路由中使用路由守卫
219 0
|
测试技术 虚拟化 iOS开发
iOS自动化测试方案(二):Xcode开发者工具构建WDA应用到iphone
这篇文章是iOS自动化测试方案的第二部分,详细介绍了在Xcode开发者工具中构建WebDriverAgent(WDA)应用到iPhone的全过程,包括环境准备、解决构建过程中可能遇到的错误,以及最终成功安装WDA到设备的方法。
1155 0
iOS自动化测试方案(二):Xcode开发者工具构建WDA应用到iphone
|
移动开发 前端开发 JavaScript
技术经验分享:Canvas入门到高级详解(上)
技术经验分享:Canvas入门到高级详解(上)
226 0
|
负载均衡 算法 网络协议
LVS、Nginx和HAProxy负载均衡器对比总结
LVS、Nginx和HAProxy负载均衡器对比总结