小编TWO*_*ONE的帖子

Axios可以访问响应头字段

我正在使用React和Redux构建一个前端应用程序,我正在使用axios来执行我的请求.我想访问响应标题中的所有字段.在我的浏览器中,我可以检查标题,我可以看到我需要的所有字段都存在(例如令牌,uid等等),但是当我打电话时

const request = axios.post(`${ROOT_URL}/auth/sign_in`, props);
request.then((response)=>{
  console.log(response.headers);
});
Run Code Online (Sandbox Code Playgroud)

我得到了

Object {content-type: "application/json; charset=utf-8", cache-control: "max-age=0, private, must-revalidate"}
Run Code Online (Sandbox Code Playgroud)

这是我的浏览器网络选项卡,因为您可以看到所有其他字段都存在.

在此输入图像描述

最好成绩.

http-headers es6-promise axios

117
推荐指数
8
解决办法
7万
查看次数

在Redux商店中存储凭据是一种很好的做法吗?

我正在尝试开发一个用于学习目的的React/Redux应用程序,我想知道我到目前为止所做的是一个好的做法还是不推荐.我必须处理的第一件事是处理授权请求.我有一个restfull api Rails后端.此服务器响应附加在头参数(如access-token)中的登录请求.此访问令牌仅对下一个请求有效,而下一个请求又返回对下一个请求有效的新令牌,依此类推.

我以这种方式实现了这个流程:商店调度执行登录请求的动作,传递用户名和密码.然后,当响应准备就绪时,我将凭证存储在redux存储中.当我需要执行授权请求时,我在头请求中设置这些参数.当我收到响应时,我使用从响应中获得的新凭据更新商店中的凭据.

这里我的代码更清晰:

import { combineReducers } from 'redux'
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';

const initialState = {
  currentUser: {
    credentials: {},
    user: {}
  },
  test: {},
  users: []
}

export const SUBMIT_LOGIN = 'SUBMIT_LOGIN'
export const SET_USER = 'SET_USER'
export const TEST = 'TEST'
export const SET_USERS = 'SET_USERS'
export const SET_CREDENTIALS = 'SET_CREDENTIALS'

//actions
const submitLogin = () => (dispatch) => {
  return postLoginRequest()
    .then(response => {
      dispatch(setCredentials(
        response.headers.get('access-token'),
        response.headers.get('client'), …
Run Code Online (Sandbox Code Playgroud)

authentication cors access-token reactjs redux

9
推荐指数
1
解决办法
3102
查看次数

ArrayAdapter文本和图像

在我的活动中,我实现了一个包含一些文件名称的列表.每个列表的项目都指的是我想要显示图像名称和引用图像缩略图的布局.我可以使用ArrayAdapter显示名称,但我不知道如何插入图像缩略图.引用的所有图像都保留在sd_card中,并且我有它们的路径.这是单行布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="horizontal" >

<ImageView
    android:id="@+id/imageView"
    android:layout_width="36dp"
    android:layout_height="wrap_content"
    android:src="@drawable/btn_nav_background_default" />

<TextView
    android:id="@+id/titoloTv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

和活动的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<Button
    android:id="@+id/creaButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="Crea una nuova realtà aumentata" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="Ar già create"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


</ListView>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

和活动代码固有的适配器.

    ArrayAdapter<?> arrayAdapter = new ArrayAdapter<String>(this,R.layout.row,R.id.titoloTv,targetName);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
           @Override  
           public void onItemClick(AdapterView<?> adapter, final View componente, int …
Run Code Online (Sandbox Code Playgroud)

android image adapter

6
推荐指数
2
解决办法
4万
查看次数