鍍金池/ 問答/HTML/ Dva fetch為何返回的是Promise而不是請(qǐng)求的數(shù)據(jù)

Dva fetch為何返回的是Promise而不是請(qǐng)求的數(shù)據(jù)

使用dva 的fetch訪問網(wǎng)絡(luò),已成功返回?cái)?shù)據(jù),為何fetch 返回的是promise 而不是請(qǐng)求的數(shù)據(jù)

import fetch from 'dva/fetch';

function parseJSON(response) {
  return response.json();
}

function checkStatus(response) {
  if (response.status >= 200 && response.status < 300) {
    return response;
  }

  const error = new Error(response.statusText);
  error.response = response;
  throw error;
}

/**
 * Requests a URL, returning a promise.
 *
 * @param  {string} url       The URL we want to request
 * @param  {object} [options] The options we want to pass to "fetch"
 * @return {object}           An object containing either "data" or "err"
 */
export default function request(url, options) {
  return fetch(url, options)
    .then(checkStatus)
    .then(parseJSON)
    .then(data => ({ data }))
    .catch(err => ({ err }));
}

請(qǐng)求 此處data為一個(gè)Promise

effects: {
    *login({payload }, { call, put }) {  // eslint-disable-line
      const {data} = yield call(login,payload);
      if(data.success){
        routerRedux.push('./users')
      }
    },
  },

service 被model調(diào)用

export function login(data)
{
  let _data = fetch(url,data);
  console.log(_data);
  return _data;
}

網(wǎng)絡(luò)數(shù)據(jù)

問題出現(xiàn)的環(huán)境背景及自己嘗試過(guò)哪些方法

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

回答
編輯回答
玄鳥

我調(diào)用的時(shí)候取到的就是返回的數(shù)據(jù)

2017年7月9日 21:03