我正在尝试使用react-native、axios 和 Expo 发送 JSON 数据,但是当我在应用程序上按“发送”时,我收到此警告:
可能未处理的承诺拒绝,错误:网络错误
当我尝试通过 POSTman 发送通知(JSON)时,我的 API 正确接收通知(JSON),但是当我尝试使用 axios 发送通知时,我收到上述警告消息,所以 React 可能没有正确发送数据。
export default class NotificationsInput extends React.Component {
state = {
token: '',
title: '',
body: ''
}
handleToken = event => {
this.setState({ token: event.target.value })
}
handleTitle = event => {
this.setState({ title: event.target.value })
}
handleBody = event => {
this.setState({ body: event.target.value })
}
handleSubmit = event => {
event.preventDefault();
let notification = JSON.stringify({
token: this.state.token,
title: this.state.title,
body: this.state.body
}) …Run Code Online (Sandbox Code Playgroud) 在我的 Remix 应用程序中,我尝试根据状态变量的值有条件地显示 UI 小部件。这是我的代码。
import { useState } from "react";
import type { LinksFunction } from "remix";
import stylesUrl from "../styles/index.css";
export const links: LinksFunction = () => {
return [
{
rel: "stylesheet",
href: stylesUrl
}
];
};
export default function Index() {
const [isMenuOpen,setMenuOpen] = useState(false)
function toggleNav(){
window.alert("hh") // no alert is shown
console.log("hi") // no console statement is printed
setMenuOpen(!isMenuOpen)
}
return (
<div className="landing">
<button onClick={toggleNav}>test</button>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
但是,toggleNav单击按钮似乎不会触发功能。我在控制台中看不到任何警报或输出。
我不明白为什么它不起作用。如果有人能指出我在这里做错了什么,那就太好了。TIA。
我正在尝试在 CloudFlare Pages 上部署我的 NextJS 应用程序。但是我在构建应用程序过程中遇到错误:
Error: Asset ".next/cache/webpack/client-production/0.pack" is over the 25MiB limit. Size: 38331968 bytes
这是我的部署设置:
Build command:
next build
Build output directory:
/.next
Root directory:
/
Environment variables:
None
Run Code Online (Sandbox Code Playgroud)
CloudFlare Pages 每个文件的大小限制为 25MB,而上述文件超出了该限制。我不知道这个文件是做什么用的。有没有办法减少它的大小(或只是删除它)?
我正在建立一个网站,我的后端我在django,前端使用PHP.问题是我试图做一个ajax调用php (localhost),django (localhost:8000)每当我尝试所以它给mes下面的错误
$(document).on('click', '.login', function(event) {
var username = $('#username').val();
var token = $('#token').val();
$.ajax({
type: "POST",
url: "http://localhost:8000/project/login/uid=" + username + ";token=" + token,
success: function (html) {
alert(html);
}
});
});
Run Code Online (Sandbox Code Playgroud)
ajax代码是
$(document).on('click', '.login', function(event) {
var username = $('#username').val();
var token = $('#token').val();
$.ajax({
type: "POST",
url: "http://localhost:8000/project/login/uid=" + username + ";token=" + token,
success: function (html) {
alert(html);
}
});
});
Run Code Online (Sandbox Code Playgroud)
我如何从我的前端到localhost:8000上的django后端进行ajax调用
今天是个好日子!我一直想知道nodejs mysql beginTransaction是否在我的池中使用多个连接(如果我的事务中有多个查询),或者它是否仅使用单个连接,直到它被提交?
我想让用户从我的 TypeScript NPM 包的子文件夹中导入。例如,如果TypeScript代码的目录结构如下,
- lib
- src
- server
- react
Run Code Online (Sandbox Code Playgroud)
我的包的用户应该能够从子文件夹导入package-name/react,package-name/server等等。
我的 tsconfig.json 如下。
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": true,
"jsx": "react",
"esModuleInterop": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}
Run Code Online (Sandbox Code Playgroud)
当“outDir”设置为项目根目录时,我可以这样做,但是文件结构很混乱。有人可以指出我在保留的同时执行此操作的方法(从子模块导入)"outDir": "./lib"吗?非常感谢有用的答案。提前致谢。
我正在处理有关在React中更新状态以进行验证的许多问题,无论如何,我总是在渲染或类似操作之后更新状态,无论如何,我看到很多人使用中的回调函数来解决此问题setState,但它总是抛出以下警告。
警告:已从更新函数内部安排了更新(setState,replaceState或forceUpdate)。更新函数应该是纯函数,且副作用为零。考虑使用componentDidUpdate或回调。
我尝试在内部进行更新componentDidUpdate,但这会导致无限循环。
这是我setState的回调函数。
state = {
index: 0,
activeInput: '',
errors: {
error: false,
errorNombre: false,
errorCuil: false,
errorEmail: false,
errorContrasena: false,
errorCalle: false,
errorNumero: false,
errorProvincia: false,
errorLocalidad: false
},
values: {...this.props.initialValues}
};
_onChangeValue = (name, value) => {
this.setState(prevState => {
return {
values: {
...prevState.values,
[name]: value
}
}, this.validate(name)
})
};
Run Code Online (Sandbox Code Playgroud)
这是Validate Function,是一个开关,所以我花了更长的时间,但问题可能是每种情况下都有另一个setState ...
validate = input => {
switch(input){
case 'nombre':
let { nombre } = this.state.values
let …Run Code Online (Sandbox Code Playgroud) 我正在我的 React-Native 应用程序中使用react-native-fbsdk. 我不明白为什么“使用 facebook 应用程序登录”不起作用。当用户单击此按钮而不是在 Web 视图中输入其凭据时,LoginManager回调似乎永远不会被触发。
以下是发生的情况的视频:https://i.imgur.com/1XeJC1o.mp4
这个问题似乎可能是常见问题解答中的这个问题,但我相信我的AppDelegate.m文件Info.plist设置正确。
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <SentryReactNative/RNSentry.h>
#import <GoogleMaps/GoogleMaps.h>
#import <react-native-branch/RNBranch.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#import <CodePush/CodePush.h>
#import <AppCenterReactNativeCrashes/AppCenterReactNativeCrashes.h>
#import <AppCenterReactNativeAnalytics/AppCenterReactNativeAnalytics.h>
#import <AppCenterReactNative/AppCenterReactNative.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES];
NSURL *jsCodeLocation;
[AppCenterReactNativeCrashes registerWithAutomaticProcessing]; // Initialize AppCenter crashes
[AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true]; // Initialize AppCenter analytics
[AppCenterReactNative register]; // Initialize AppCenter
[GMSServices provideAPIKey:@"myAPiKey"];
[[FBSDKApplicationDelegate sharedInstance] application:application …Run Code Online (Sandbox Code Playgroud) 我的目标很简单,在反应日期选择器中显示数据库中的日期。从我的数据库中,我得到了 string "2019/10/26 15:05",但是当selected它返回时设置它,
从 v2.0.0-beta.1 date-fns 开始,不接受字符串作为参数。请使用
parseISO解析字符串
<DatePicker
dateFormat="dd-MM-yyyy HH:mm"
showTimeSelect
timeFormat="HH:mm"
timeIntervals={1}
selectsEnd
startDate={this.state.beginDate}
endDate={this.state.endDate}
selected={this.state.endDate}
onChange={this.selectEndDate} />
Run Code Online (Sandbox Code Playgroud)
我也尝试过date-fns,parseISO但仍然不起作用。我应该怎么办?
我正在从express.js 服务器中的云存储桶流式传输视频文件,并且能够成功将该流传输到前端中的视频元素。但是,由于视频内容现在是渐进加载的,因此我无法搜索加载的视频。
我用于从云存储对象获取视频流的 Node.js 代码如下。
async function getVideoStream(gcloudFileName,res){
const bucket = storage.bucket(process.env.GCS_BUCKET);
const remoteFile = bucket.file(gcloudFileName);
return remoteFile.createReadStream().pipe(res)
}
Run Code Online (Sandbox Code Playgroud)
如何使该视频流可以被搜索,以便用户可以在前端搜索视频? 非常感谢有用的建议。
编辑:
我尝试了@Rafael的答案并在一定程度上得到了它的工作,但现在的问题是在交付视频的前几个块后流停止了。与此同时,视频也停止播放。
javascript ×3
reactjs ×3
node.js ×2
react-native ×2
ajax ×1
axios ×1
django ×1
expo ×1
express ×1
import ×1
mysql ×1
next.js ×1
node-mysql ×1
npm ×1
php ×1
remix.run ×1
setstate ×1
subdirectory ×1
typescript ×1
warnings ×1
webpack ×1