es6,ajax里的格式求科普

报错提示loadAuthData(...).then(...).fail is not a function

代码如下:

loadData(){
    this.loading('show');
    var param = {
        userId:this.id
    };
    var _this = this;
    common.loadAuthData().then((data)=> {
    
        console.log(data);
    
        _this.username = data.result.username;
        _this.idCard = data.result.idNum;
        _this.reidCard = data.result.idNum;
        _this.firstName = data.result.firstName;
        _this.lastName = data.result.lastName
    
    }).fail(()=> {
        _this.broadcast('请求用户数据失败,请重试');
    }).always(()=> {
        _this.loading('hide');
    })
},
阅读 4.2k
5 个回答

别告诉我你是直接在浏览器上运行的...

新手上路,请多包涵

是不是要编译啊

给你推荐一下fetch吗?
redux中文官网http://cn.redux.js.org/docs/a...(高级/异步 Action Creator 目录)
SF上面一篇fetch的介绍https://segmentfault.com/a/11...

function fetchPosts(subreddit) {
  return dispatch => {
    dispatch(requestPosts(subreddit))
    return fetch(`http://www.reddit.com/r/${subreddit}.json`)
      .then(response => response.json())
      .then(json => dispatch(receivePosts(subreddit, json)))
  }
}

宣传栏