redux fetch body不能用于没有cors模式

ary*_*yan 12 javascript fetch reactjs redux fetch-api

我有这个调用函数的动作:

dispatch(Api({url: "my_url", method: "POST", data: data}))
Run Code Online (Sandbox Code Playgroud)

这里我将数组作为数据传递..

import fetch from 'isomorphic-fetch'

export default function Api({url, method, headers, data}={}){
    return dispatch => {

        console.log(data)
        console.log(url)
        console.log(method)
        console.log(JSON.stringify(data))
        let response = fetch(url, {
            mode: 'no-cors',
            method: method || null,
            body: data || null, 
        }).then(function(response) {
            console.log("response");
             console.log(response)
            });

    }
}
Run Code Online (Sandbox Code Playgroud)

在这里,我用fetchmode:'no-cors',我想我想过去的所有arguements ..在这里,我的身体是我作为传递简单arguement阵列..

当我看到响应时,它就像:

body: null
bodyUsed: false
headers: Headers
ok: false
status: 0
statusText: ""
type: "opaque"
url:""
Run Code Online (Sandbox Code Playgroud)

在这里我的身体没被使用..

这里有什么问题?需要帮忙

Mar*_*rco 27

你得到了opaque response[ 1 ] [ 2 ],因为你正在使用fetch mode: 'no-cors'.您需要使用mode: 'cors'并且服务器需要发送所需的CORS头[ 3 ]才能访问响应.