UNPKG

tbom

Version:

Taobao Open Platform Modules

58 lines (50 loc) 1.25 kB
import {createElement, Component} from 'rax'; import View from 'tboc-view'; import Text from 'tboc-text'; import styles from '../common/style.css'; import { fetch } from '../../../src/index';; class FetchDemo extends Component { state = { fetchData: null, jsonData: null } doFetch = () => { fetch('https://g.alicdn.com/??kissy/k/6.2.4/seed-min.js') .then((response) => { return response.text() }).then((text) => { this.setState({ fetchData: text.slice(1, 100) + '...' }); }).catch((ex) => { this.setState({ fetchData: JSON.stringify(ex) }); }) } render() { return ( <View style={styles.app}> <Text style={demoStyles.text}>Fetch 请求结果:{this.state.fetchData}</Text> <View clickable={true}onPress={this.doFetch} onClick={this.doFetch} style={demoStyles.button}>发起 Fetch 请求</View> </View> ); } } const demoStyles = { text: { paddingLeft: 20, paddingRight: 20 }, button: { borderWidth: 2, borderColor: '#CCC', borderStyle: 'solid', paddingLeft: 20, paddingRight: 20, marginTop: 40, marginBottom: 40, backgroundColor: '#EEE' } } module.exports = FetchDemo;