当用户刷新我的应用程序中的其他页面时,我需要重定向到主页。我正在使用React router
v4 和redux
. 由于商店在重新加载时丢失,用户重新加载的页面现在是空的,因此我想将他带回不需要任何先前存储数据的页面。我不想在localStorage
.
我试图在事件中处理此问题,onload
但没有奏效:
window.onload = function() {
window.location.path = '/aaaa/' + getCurrentConfig();
};
Run Code Online (Sandbox Code Playgroud) 我从 API 获取一个对象,并在其中使用其他 API 响应创建新对象,例如:
API响应1:Obj: {a: 1, b: 2}
API响应2:3
创建对象:Obj.c = 3
最终结果: 对象:{a: 1, b: 2, c: 3}
console.log(Obj) return Obj: {a: 1, b: 2, c: 3}
console.log(Obj.c) return undefined
Run Code Online (Sandbox Code Playgroud)
console.log
当我尝试在属性中给出 a之后时,我没有得到.map
,我无法访问创建的属性,返回undefined
。但是,当我console.log
在任何对象上给出 a 时,创建的属性就在那里。
async getGeneralInfo(token, seed) {
try {
API_HEADER.headers.Authorization = token;
let responseAvaliableCoins = await axios.get(
BASE_URL + "/coin",
API_HEADER
);
let avaliableCoins = responseAvaliableCoins.data.data.coins;
avaliableCoins.map(async (coin, index) => {
if (coin.status …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Typescript 在 React 中编写一个高阶组件,该组件接收道具,“消耗”其中一个,然后将其余部分传递给子组件。
function testConnect<T>(Child: React.ComponentType<T>): React.ComponentType<T> {
type InitialState = {
iS: StoreShape.State;
};
type LAP = InitialState & T;
const Connector = (props: LAP) => {
const { iS, ...rest } = props;
// do something with iS
return (
<Child // Visual Studio complains about this line.
{...rest}
/>
);
};
return Connector;
}
Run Code Online (Sandbox Code Playgroud)
但是,这失败并出现错误: 'Pick<LAP, Exclude<keyof T, "iS">>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different …
我今天向您求助是因为我对硒有疑问。我的目标是制作一个完全自动化的机器人,它可以创建一个包含解析详细信息(邮件、通行证、出生日期...)的帐户。到目前为止,我已经几乎创建了该机器人(我只需要访问 Gmail 并获得确认)代码)。
我的问题就在这里,因为我已经尝试了很多东西,我有一个Failed to load resource: the server responded with a status of 429 ()
所以,我猜,Instagram 阻止了我。我怎样才能绕过这个?
我正在尝试根据这篇文章在centos 7 上配置 Django这里
我安装了
sudo yum install python-pip python-devel postgresql-server postgresql-devel postgresql-contrib gcc nginx
Run Code Online (Sandbox Code Playgroud)
在像创建数据库一样为 Django 设置 PostgreSQL 之后,......我尝试在 virtualenv 上安装 psycopg2
pip install django gunicorn psycopg2
Run Code Online (Sandbox Code Playgroud)
但是我遇到了这个错误,有人可以帮助我吗?
Collecting psycopg2
Using cached psycopg2-2.6.2.tar.gz
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... error
Complete output from command /usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-n0buiow5/psycopg2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jk1w8dv1-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.4
creating build/lib.linux-x86_64-3.4/psycopg2 …
Run Code Online (Sandbox Code Playgroud) 我想向this
object by添加新的键和值destructuring assignment
,但它出错了:
Uncaught SyntaxError: Unexpected token :
Run Code Online (Sandbox Code Playgroud)
让我们看看我的例子,假设我有obj
数据对象:
const obj = {
'a':'1',
'b':'2',
'c':'3',
};
Run Code Online (Sandbox Code Playgroud)
现在我想将此数据绑定到this
对象,这意味着我们想要:
console.log(this.a); //=> "1"
Run Code Online (Sandbox Code Playgroud)
因此,在解构赋值中,我这样写:
{
a: this.a,
b: this.b,
c: this.c,
} = obj;
Run Code Online (Sandbox Code Playgroud)
但它陷入了错误:
Uncaught SyntaxError: Unexpected token :
Run Code Online (Sandbox Code Playgroud)
我不使用const
,let
或者var
因为this
对象已经被声明。我怎样才能达到我的愿望?有可能destructuring assignment
吗?
简单地可以通过正常分配:
this.a = obj.a;
this.b = obj.b;
this.c = obj.c;
Run Code Online (Sandbox Code Playgroud)
我只是想要正确的新JavaScript
代码和漂亮的代码。
我在我的项目中使用redux
和redux-saga
。现在使用 WebSocket 我在调用FETCH_SUCCESS
redux
套接字响应回调中的操作时遇到问题。我也尝试将回调设为生成器,但效果不佳。
function* websocketSaga() {
const socket = new SockJS(`${CONFIG.API_URL}/ws`);
const stomp = Stomp.over(socket);
const token = yield select(selectToken);
stomp.connect(
{
Authorization: `Bearer ${token}`,
},
frame => {
stomp.subscribe('/queue/data', message => {
const response = JSON.parse(message.body);
console.log(response); // here is the proper response, it works
put({
type: FETCH_SUCCESS, // here the FETCH_SUCCESS action is not called
payload: response.dataResponse,
});
});
...
....
}
);
}
Run Code Online (Sandbox Code Playgroud)
或者也许这个 WebSocket 应该以完全不同的方式实现redux-saga
?
我想让我的网络应用程序像移动应用程序一样工作。这意味着当用户按回时,他们希望弹出窗口关闭,而不是整个页面发生变化。
我的最终目标是让它在模态打开时后退按钮现在将关闭模态,如果他们再次单击它会返回。
我尝试了几种方法,尽管很接近,但它们从未始终如一地响应。 https://codesandbox.io/s/github/subwaymatch/react-disable-back-button-example-v2
任何人都有我正在寻找的经过验证的工作版本?
我正在尝试构建一个包含多个“分组”复选框的表单,使用react-form-hook
Material UI
.
这些复选框是从 HTTP 请求异步创建的。
我想提供一组对象 ID 作为默认值:
defaultValues: { boat_ids: trip?.boats.map(boat => boat.id.toString()) || [] }
此外,当我选择或取消选择一个复选框时,我想将对象的ID添加/删除到react-hook-form
.
IE。( boat_ids: [25, 29, 4]
)
我怎样才能做到这一点?
这是我试图重现该问题的示例。
加分点,使用 Yup 验证最小选定复选框
boat_ids: Yup.array() .min(2, "")
reactjs ×5
javascript ×4
python ×2
react-router ×2
redux ×2
api ×1
arrays ×1
axios ×1
camera ×1
centos ×1
checkbox ×1
django ×1
fingerprint ×1
forms ×1
instagram ×1
material-ui ×1
object ×1
postgresql ×1
react-native ×1
react-redux ×1
redux-saga ×1
stomp ×1
typescript ×1
websocket ×1