当我使用react-native init(RN版本0.29.1)创建一个全新的项目并将渲染方法中的提取放到公共Facebook演示电影API时,它会抛出一个Network Request Failed.有一个非常无用的堆栈跟踪,我无法在chrome控制台中调试网络请求.这是我发送的提取:
fetch('http://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
return responseJson.movies;
})
.catch((error) => {
console.error(error);
});
Run Code Online (Sandbox Code Playgroud) 我正在构建一个非常简单的api和react-native应用程序.服务器运行良好(使用PostMan测试)但应用程序不会调用服务器.当axios必须发送帖子请求时它会阻止(见下文).
我很绝望:-(在这里度过太多时间.请,如果你能帮助我...
这是我的代码LogIn页面.它派遣动作创建者(使用redux)给出电子邮件和密码:
...
const LogIn = React.createClass({
submitLogin() {
// log in the server
if (this.props.email !== '' && this.props.psw !== '') {
if (this.props.valid === true) {
this.props.dispatch(logIn(this.props.email, this.props.psw));
} else {
this.props.dispatch(errorTyping());
}
}
},
...
Run Code Online (Sandbox Code Playgroud)
电子邮件和密码被检索并发送给动作创建者:
import axios from 'axios';
import { SIGNIN_URL, SIGNUP_URL } from '../api';
// import { addAlert } from './alerts';
exports.logIn = (email, password) => {
return function (dispatch) {
console.log(email);
console.log(password);
console.log(SIGNIN_URL);
return axios.post(SIGNIN_URL, { email, password })
.then(
(response) => …Run Code Online (Sandbox Code Playgroud)