js return new Promise resoluve

js return new Promise resoluve

searchFun: function(codes) {
    return new Promise(resolve = >{
        axios.post(url, {}).then(res = >{
            if (res.data.success === true) {
                console.log('res.data:', res.data);
                if (res.data.data.list.length > 0) {
                    resolve(res.data.data.list);
                }
            } else {
                this.$Modal.error({
                    title: '提示',
                    content: '提示内容'
                });
            }
        }).
        catch(() = >{
            this.$Modal.error({
                title: '提示',
                content: '提示内容'
            });
        });
    }
}
this.searchFun(codeNumber).then(rep = >{
    this.print(rep);
});

 

posted @ 2019-12-10 15:02  wxid_m2pywu7fxu1f  阅读(585)  评论(0编辑  收藏  举报