()
| 20 | } |
| 21 | |
| 22 | componentWillMount() { |
| 23 | // P.S: 在 Vue Demo 中,数据都是直接从后端 API 中获取 |
| 24 | // 而这里可以先直接从 state 中获取,获取不到才从服务器获取 |
| 25 | // (强制刷新页面会导致 state 被清空) |
| 26 | let { msg: { msgs }, params: { msgId } } = this.props |
| 27 | |
| 28 | let msg = msgs.filter(({ id }) => id === msgId)[0] |
| 29 | msg ? this.setState({ msg }) : this.fetchMsgFromAPI(msgId) |
| 30 | } |
| 31 | |
| 32 | fetchMsgFromAPI (msgId) { |
| 33 | msgService.fetch({ msgId }).then(msg => { |
nothing calls this directly
no test coverage detected