我有一个 reactJS 应用程序,我需要在其中读取一个大文本文件并使用文件中的数据来填充一些数组。我遇到了一些代码示例,我正在尝试实现此代码:
readTextFile = file => {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = () => {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
var allText = rawFile.responseText;
console.log("allText: ", allText);
this.setState({
fundData: allText
});
}
}
};
rawFile.send(null);
};
Run Code Online (Sandbox Code Playgroud)
通过执行这行代码来调用代码:
this.readTextFile("../text/fund_list.txt");
Run Code Online (Sandbox Code Playgroud)
当我执行应用程序时,我收到以下错误消息:
GET http://localhost:8080/text/fund_list.txt 404(未找到)
readTextFile 函数位于 account_balanc.js 代码中,我正在尝试读取文本文件 /text/fund_list.txt。该文件确实存在,所以显然我没有正确引用该文件,但我不知道为什么。
我试过 this.readTextFile("../text/fund_list.txt") 和 this.readTextFile("./text/fund_list.txt"); 但都没有奏效。我什至尝试将 fund_list.txt 移动到 /screens 文件夹并将函数调用更改为 this.readTextFile("fund_list.txt"); 但我仍然收到 404 错误消息。
任何想法为什么?
谢谢你。
我有一个 ReactJS 应用程序,我想将其提供给多个客户端。每个客户都有独特的配色方案。我需要能够导入与特定客户端相对应的 .css 文件。
例如,如果客户端 1 登录到应用程序,我想导入 client1.css。如果客户端 2 登录到应用程序,我想导入 client2.css。一旦我验证了登录信息,我就会知道客户号码。
该应用程序包含多个 .js 文件。每个 .js 文件的顶部都包含以下内容
import React from 'react';
import { Redirect } from 'react-router-dom';
import {mqRequest} from '../functions/commonFunctions.js';
import '../styles/app.css';
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以针对这种情况动态导入 .css 文件,而不是在上面的导入语句中指定 .css 文件?
谢谢
I am trying to deploy a reactJS application to heroku. I am developing on my local machine. I have the following in my package.json file:
"name": "sample-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --open"
}
Run Code Online (Sandbox Code Playgroud)
When testing on my local machine, I type in "npm start" from a command prompt and my browser opens to localhost:8080 and my application starts up.
When I deployed the application to the heroku service and tried to start the application, …
我有一个reactJS应用程序,在其中提示用户输入一些信息。这是要求用户从<select>对象中选择一个选项并在输入框中输入文本字符串的代码:
<div className="container">
<div className="row">
<div className="col-12 test-left text_15">
<label>Select one of the following questions to answer</label>
</div>
</div>
<div className="row">
<div className="col-12 text_15">
<select className="text_15"> value={currentComponent.state.securityQuestion} onChange={(event) => this.saveQuestion(event)}>
<option value="0">What is you mother's maiden name?</option>
<option value="1">What elementary school did you attend?</option>
<option value="2">What was the name of your first pet?</option>
<option value="3">What city were you born in?</option>
</select>
</div>
</div>
</div>
<div className="spacerAfterButton">
</div>
<div className="container">
<div className="row">
<div className="col-12 text-left text_15">
<label>Provide the answer …Run Code Online (Sandbox Code Playgroud)