0

我正在使用 Flux 和 axios 进行 API 调用反应,我已经实现了嵌套 API 调用,我从 API 正确获取数据,它在控制台中正确显示,但问题是嵌套 API 调用数据未在组件中呈现,这里是我的代码

loadCategoryProducts(action) {

    axios.post(API, {
         "query": 'query {ProductListQuery(category :"'+action.params.category+'", subcategory :"'+action.params.subcategory+'"){productinfo{partterminologyid,aliasname,partterminologyname,usedescription,categoryname,subcategoryname}worldpacinfo{worldpaccategoryid,basevehicleidnumber,parttypeidnumber,branddescription,detaileddescription,Note,popularity,price,productimageurl,productpartnumber,productthumburl,ThumbURL,available,Part}}}',
    }).then(resp => {
        if(resp.data.data){
            var productsArr = resp.data.data['ProductListQuery'];
            var count = productsArr.length;
            productsArr.map(function(value, index) {
                if(value.worldpacinfo.basevehicleidnumber!='undefined') {
                    axios.post(API, {
                        "query": 'query {PriceQuery(basevehicleidnumber :"'+value.worldpacinfo.basevehicleidnumber+'",parttypeidnumber:"'+value.worldpacinfo.parttypeidnumber+'",productpartnumber:"'+value.worldpacinfo.productpartnumber+'"){corefee,retailprice}}',
                    }).then(resp1 => {
                        value.worldpacinfo['retailprice']=resp1.data.data.PriceQuery.retailprice;
                        value.worldpacinfo['corefee']=resp1.data.data.PriceQuery.corefee;
                    }).catch((err) => {
                        console.log(err);
                    });
                }
            })
        }
        //console.log(productsArr);
        this.product = productsArr;
        this.emit("change");
    }).catch((err) => {
            console.log(err);
    });
}

我已经在 componentWillMount 上调用了这个方法

4

0 回答 0