import React, { Component } from 'react'; import './index.less'; import Icon from '../Icon'; export default class OtherAnswer extends Component { constructor(props) { super(props); this.Text = null; this.state = { show: false, more: false }; this.checkHeight(); } checkHeight() { if (this.Text != null) { if (this.Text.offsetHeight > 80) { this.setState({ more: true }); } } else { setTimeout(() => { this.checkHeight(); }, 1); } } render() { const { data } = this.props; const { show, more } = this.state; return (
提问
{data.content}
回答
{ this.Text = ref; }} className="desc" dangerouslySetInnerHTML={{ __html: data.answer }} /> {more && show && this.setState({ show: false })} />} {more && !show && this.setState({ show: true })} />}
); } }