Upon arriving on the Nuxt page, I have noticed that occasionally the fetch hook fails to call the API, resulting in me receiving cached data instead

In my Nuxt app, I have a page referred to as pageA. The fetch hook on this page calls a Vuex action that in turn calls an API:

// pageA
//template
<componentA />

//script, fetch hook on pageA
    try {
      await store.dispatch("myList");
    } catch (e) {
      error({
        message: "error"
      });
    }
// my store
export const state = () => ({
  listItems: null,
});

export const actions = {
  async myList({ commit }) {
    await axios
      .get(
        `${url}`,
        {
          headers: {
            ["key"]: "abcd123"
          }
        }
      )
      .then(data => {
        if(data && data.status === 200){
          let results = data.data
          list = JSON.parse(JSON.stringify(results));
          commit("SET_LIST", list);
        }
      })
      .catch(error => {
        console.log(error);
      });
  },
}
SET_LIST(state, list) {
  state.listItems = list;
},

The data from listItem is then accessed from the store state in my <componentA> that is imported into pageA:

//this is componentA:
//template 

<div v-for="lists in list" :key="list.id"
<componentB
  :name="lists.name"
  :color="lists.color"
  // and so on
></componentB>

//script
  computed: {
    ...mapState(["list"])
  }

The API myList called from the fetch hook on pageA works most of the time, but there are instances when it is not triggered upon page load (or when returning to the page). In contrast, another API called in the fetch hook of componentB within the same architecture (via the store) always works upon page load. Can anyone shed light on why this might be happening?

Answer №1

Encountering a similar issue led me to explore the intricacies of the fetch caching mechanism and timestamps. Ultimately, I resolved it by opting for asyncData, or alternatively, employing a different approach such as utilizing refresh and invoking this.$fetch on it.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the clarification on AngularJs' ng-options?

In my demo, I have a small setup. Essentially, it consists of a select element with the following data: address: { select: { code: "0", name: "Select proof of address" }, letter: { ...

Generate the entity and then transfer the data into an array

I am dealing with multi-level hierarchies that need to be displayed in a select list. Once the user selects values from the table column, they should be able to filter by clicking on the column. var name = ['Akansha', 'Navya']; var age ...

Error encountered with MobileFirst version 8 and Angular JS v1.5.3 integration using Bootstrap

I am encountering an issue with my Cordova application that integrates with MobileFirst Platform version 8, Ionic version 1.3.1, and AngularJS version 1.5.3. Upon bootstrapping AngularJS to connect the app to MobileFirst Platform, I encounter the following ...

Can an event be initiated on dynamically loaded iframe content within a document using the jQuery "on" method?

Is there a way to include mousemove and keypress events for iframes? The code provided seems to work well with existing iframes on the page, but it doesn't seem to work for dynamically created frames in the document using JavaScript. $('iframe&a ...

Obtaining a group object when the property value matches the itemSearch criteria

What is the best way to extract specific objects from a group when one of their properties has an array value, specifically using _.lodash/underscore? { "tileRecords" : [ { "tileName" : "Fama Brown", "tileGroup" : ["Polished", "Matt", ...

When you utilize React.createRef, the value of `current` is consistently null

I attempted to follow the steps outlined in this guide. Despite my efforts, I seem to be overlooking something as I can't figure out why current always returns null in this specific scenario. class App extends React.PureComponent { constructor(pro ...

Implement lazy loading in VueJS when using the v-for directive on components

I am trying to optimize the loading speed of my website. Currently, all the projects are loaded on the initial page load which is causing a delay. I want to implement lazy loading for these components, specifically for a component called project-card. Howe ...

As the user types, the DD/MM/YYYY format will automatically be recognized in the

In my React component, I have an input box meant for entering a date of birth. The requirement is to automatically insert a / after each relevant section, like 30/03/2017 I am looking for something similar to this concept, but for date of birth instead of ...

What is causing the col divs to stack instead of aligning next to each other?

I am a newcomer to Vue.JS and front-end programming in general. I wanted to create a page with a fixed sidebar and content below a navbar. Here is the configuration I tried: <template> <div class="container-fluid"> <div class ...

React components can be used to dynamically render and display an array of objects through methods like reduce and

Here's the scenario at hand: (https://codesandbox.io/s/8p21n6p09l) I have an array of objects (referred to as modules) structured like this: const modules = [ { thematicArea: "Topic 1", id: 1, name: "Building assertive attitude", d ...

JavaScript can be used to arrange a table in both ascending and descending order by simply clicking on the header

window.addEventListener('DOMContentLoaded', () => { let dir = "dsc"; th = document.getElementsByTagName('th'); for(let c=0; c < th.length; c++){ th[c].addEventListener('click',item(c)); } ...

Get the Vue.js and Python Flask file downloaded

My Flask server serves as a REST server. Within my Flask route, here is the setup: @app.route('/v1/download', methods=['POST']) def download_tissue(): f = open('path_to_zip_file', 'rb') // or r for text file ...

Is there a modal confirmation feature available in Salesforce?

if ((Modal.confirm && Modal.confirm('some unique text')) || (!Modal.confirm && window.confirm('same but different text'))) navigateToUrl('another link here','ANOTHER DETAIL','submit'); I am curious about t ...

What is the best way to incorporate an immediately invoked function expression (IIFE) within the return statement of a React

I currently have a modal that pops up when the user clicks a button on my page and it's functioning perfectly: render() { return ( <div> <section> <button onClick={() => this.refs.simpleDialog.show()}> ...

How can I pass an array to props in Vue and PHP?

Recently I started delving into Vue, and I'm struggling to grasp the purpose of props. Let me provide some context with a simple PHP array: $vegetables = ['apple', 'strawberry', 'banana']; Now, my goal is to use this ar ...

Communicating PHP variables with JavaScript through AJAX in a chat application

Hello there! I am currently in the process of developing a chat application for my website that includes user registration and login. My backend server is built using NodeJS to leverage SocketIO capabilities. Within my index.php file, I have implemented ...

modifying button depending on the state of bootstrap collapse

I'm currently utilizing Bootstrap in my project. Here is the snippet of HTML code I have: <div class="row"> <button id="dog-btn" data-toggle="collapse" data-target="#dog-section" onclick=" ...

npm encountered an issue: EPERM error - the operation is not permitted and cannot unlink the file

Operating System: Windows 10. NPM Version: 6.9.0 Node Version: 12.4.0 I am currently developing an Expo application. I am attempting to install all the necessary packages for my Expo application using 'npm install'. However, I encountered an err ...

Amplify may encounter undefined application environment variables when serving the application

I am currently utilizing a Vue.js application hosted on AWS Amplify. In Vue, environment variables can be set globally using .env files. During development and production modes, I have separate .env files with different values for these variables. While b ...

Deprecated: Asynchronous XMLHttpRequest on the primary thread is no longer supported

Currently, I am working on the extjs framework. I have developed an application using extjs. However, whenever I launch the application in the browser, I encounter some warnings in the console. The warning message states that Synchronous XMLHttpRequest o ...