UNPKG

tbom

Version:

Taobao Open Platform Modules

61 lines (54 loc) 1.3 kB
import {createElement, Component} from 'rax'; import View from 'tboc-view'; import Text from 'tboc-text'; import styles from '../common/style.css'; import { jsonp } from '../../../src/index'; class JsonpDemo extends Component { state = { jsonData: null } doJsonp = () => { jsonp('//t.alicdn.com/t/gettime', { method: 'jsonp', timeout: 2000, callback: 'abc', body: 'a=123&b=456&c=789', }) .then((response) => { return response.json(); }).then((json) => { this.setState({ jsonData: JSON.stringify(json) }); }).catch((ex) => { this.setState({ jsonData: JSON.stringify(ex) }); }); } render() { return ( <View style={styles.app}> <Text style={demoStyles.text}>Jsonp 请求结果:{this.state.jsonData}</Text> <View clickable={true}onPress={this.doJsonp} onClick={this.doJsonp} style={demoStyles.button}>发起 Jsonp 请求</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 = JsonpDemo;