import React, { Component } from 'react'; import axios from 'axios'; import Input from './common/Input'; import Button from './common/Button'; import Toast from './common/Toast'; import styles from './ContactPanel.cm.styl'; class ContactPanel extends Component { constructor(props) { super(props); this.state = { contact: '', content: '', }; this.handleContactChange = this.handleContactChange.bind(this); this.handleContentChange = this.handleContentChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } componentDidMount() { document.title = '小鹿快传|简单安全高效的P2P文件传输服务 - 联系我们'; } handleContactChange(value) { this.setState({ contact: value, }); } handleContentChange(e) { this.setState({ content: e.target.value, }); } handleSubmit() { const { contact, content, } = this.state; if (!contact) { Toast.error('请输入联系方式'); return; } if (!content) { Toast.error('请输入留言内容'); return; } axios.post('/api/feedback', { contact, content, }) .then((res) => { Toast.success('留言成功'); this.setState({ contact: '', content: '', }); }); } render() { const { contact, content, } = this.state; return (