从PWA缓存中未答复带有VUEX的请求

时间:2018-12-06 02:01:44

标签: vuejs2 service-worker vuex progressive-web-apps

我正在使用VUE和VUEX进行PWA。一切正常,直到尝试脱机应用程序为止,因为我在操作中VUEX无法解析来自缓存的请求。

如果我不使用VUEX,来自组件的请求会很好地发送到缓存,但是使用VUEX则会收到错误消息:

获取https://api.mercadolibre.com/items/MLM580205144净值:: ERR_FAILED

这是VUEX中请求的代码:

actions.js:

    for ( var x = 0; x <= json.results.length; x ++ ){

        if(json.results[x] !== undefined){

            var dataOfProduct = {
            id:'',
            product:'',
            description:{
                model:'',
                desc:'',
                title:''
            }

            };

            const dataItem = await fetch('https://api.mercadolibre.com/items/' + json.results[x].id );
            const jsonItem = await dataItem.json();

            const dataDesc = await fetch('https://api.mercadolibre.com/items/' + json.results[x].id + '/description');
            const jsonDesc = await dataDesc.json();

                dataOfProduct.id = json.results[x].id;
                dataOfProduct.product = jsonItem;


            if( jsonDesc.status === 404){
                jsonDesc.plain_text = 'Producto: No definido. Modelo: No definido'
            }

                let text = jsonDesc.plain_text;

                dataOfProduct.description.desc = text; 

                const product = 'Producto:';
                let resultProduct = text.match(new RegExp(product + '\\s(\\w+)', 'i'));
                if (resultProduct != null) {
                    resultProduct = resultProduct[1];
                }

                const model = 'Modelo:';
                let resultModel = text.match(new RegExp(model + '\\s(\\w+)', 'i'));
                if (resultModel != null) {
                    resultModel = resultModel[1];
                }

                dataOfProduct.description.title = resultProduct;
                dataOfProduct.description.model = resultModel;

        }

        allProducts.push( dataOfProduct );

    }

error fetch with vuex

0 个答案:

没有答案