import Taro, { Component } from '@tarojs/taro' import { View, Image } from '@tarojs/components' import ListMore from '@/c/pageDataList/listMore' import './index.scss' export default class Comment extends Component { constructor (props) { super(props) this.state = { newsList: [], isMoreAllShow: false, } } componentWillMount () { this.props.onRef(this) } getData = (newsList) => { this.setState({ newsList }) } moreHandle () { let { isMoreAllShow } = this.state isMoreAllShow = !isMoreAllShow this.setState({ isMoreAllShow }) } render () { const testImg = 'http://icon.honglounews.com/ex_banner.jpg' const { newsList, isMoreAllShow } = this.state const curArr = JSON.parse(JSON.stringify(newsList)) let cArr = isMoreAllShow ? [...curArr] : curArr.slice(0, 3) const curItems = cArr.map((item, index) => { const imgUrl = `${item.pri_image ? item.pri_image + '_xs' : testImg}` return ( {item.title} { item.create_at && {item.create_at.substring(0, 10)} } ) }) return ( {curItems} { newsList.length > 3 ? isMoreAllShow ? 收起 : 展开 : '' } { newsList.length === 0 && } ) } }