Vuex data fails to update upon browser reload in Nuxt SSR

After explaining the bug, I discovered something interesting;

Component codes

  async fetch(){ await this.$store.dispatch('bots/getBots') },
  computed: { ...mapState('bots', ['bots']) },

Store codes

export const state = () => {
  return {
    bots: []
  }
}

export const mutations = {
  UPDATE_BOTS(state, bots) {
    state.bots = bots
  }
}

export const actions = {
  getBots({commit}) {
    this.$axios.$get('url', {headers: {uid: '12345'}})
      .then(res => {
        commit('UPDATE_BOTS',res.robots)
      })
      .catch(e => {
        console.log(e)
      })
  }
}

Issue: The data loads perfectly when moving between pages via nuxt-link, but upon reloading the page the bots state becomes empty...

Discovery: While using nuxt-auth, a plugin was added to check the status of axios requests. If a request returned as unauthorized (401), it would automatically log out the user if they were logged in. However, after commenting out the plugin code, a different error related to nuxt-auth surfaced causing the initial problem. This issue has been linked to another question that can be viewed here: Nuxt-Auth Bug: Looks for autherization in any get request that has headers config

Answer №1

It is completely normal behavior. The Vuex state resides in memory, so when you refresh the page, it automatically gets cleared.

Answer №2

Choose this approach over the previous.

export const state = () => ({
    bots: []
})

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

Tips for incorporating real-time information into a highchart graph?

I'm currently working on a Highchart that utilizes AJAX and jQuery for receiving JSON data. However, I've noticed that the points on my chart only appear when I hover over it, and even then they all seem to be clustered at the top of the chart. I ...

Animation issue in Material UI autocomplete label feature

Hello, I am currently delving into the world of React and Material UI. I have been working on implementing the Material UI auto complete feature with chip functionality. You can see my progress here: https://codesandbox.io/s/runh6. Everything seems to be w ...

Accessing methods directly from within Vue template mustache syntax is a powerful

<span>{{ count }}</span> <- output: 104 why not 3 <span>{{ move() }}</span> <- output: 104 why not 4 <script> data() { return { count: 3 } }, methods: { move() { return this. ...

Dealing with unhandled exceptions while passing promises into pg-promise batch transactions

Currently, I am diving into the realm of learning express and pg promise. However, during this journey, I have encountered a puzzling issue that I suspect stems from my somewhat shaky understanding of promises. Essentially, I have crafted some functions f ...

using outlines for FontAwesome icons in React Native

I am struggling to use the fontAwesome + icon in the middle of a circle as one item. I have tried placing it inside a circle icon, but it doesn't seem to work properly. import IconFA from 'react-native-vector-icons/FontAwesome'; < ...

The word "yargs" will not activate a command within a script

I have a NodeJs script that requires parsing command line arguments. Here is the code I have written: import yargs from "yargs"; import { hideBin } from 'yargs/helpers'; //.... yargs(hideBin(process.argv)).command('--add-item ...

Retrieving fresh CSS data from earlier animated elements within a Greensock timeline

In my code, I am using a TimelineLite() to perform a series of sequential tweens with .to(). What I want to achieve is accessing the output value from one of the early tweens in order to use it for constructing later tweens. Is there any way to retrieve t ...

How to troubleshoot window.location not functioning in PHP, JavaScript, and

There is a software that utilizes Ajax Get. However, the code provided below seems to be malfunctioning. What steps can I take to rectify this issue? Javascript snippet: <script> function purchase_item(itemID) { $.ajax({ ...

What causes the alignment of text to be overridden by the presence of a floating element?

https://jsfiddle.net/u0Ltgh3e/68/ .text { width: 50%; text-align: justify; } I am currently developing a custom formatting tool for a specific purpose and I am attempting to create a two-column layout similar to the one demonstrated in this Jsfiddle l ...

Customizing the "added to cart" message in Woocommerce and setting up a notification system for customers

My main focus is on customizing the Woocommerce notation system for a personalized shopping cart experience. After some research, I stumbled upon a very helpful user response which suggested modifying the message by adding the following code snippet to th ...

Does binary search maintain its usual efficiency?

Does binary searching remain efficient and effective if an array inherits from an object? ...

Leveraging AJAX to transmit a JavaScript variable to PHP within the same webpage

I have a webpage where I want to update a PHP variable based on the value of a name attribute when a user clicks on a link. Here is an example of what I am attempting to accomplish: // PHP <?php $jsVar = $_POST['jsVar']; echo $jsVar; ...

Passing a Vue.js variable to a Laravel Eloquent model in a Laravel Blade template file

I attempted to include attribute_id in an Eloquent query, where attribute_id is a variable from Vue.js. However, I encountered the following error: Use of undefined constant attribute_id - assumed 'attribute_id' <div v-for='(attribute_ ...

Exploring the world of jQuery AJAX alongside Google's currency calculator

I'm currently working on a code that utilizes an AJAX call to access the Google currency calculator. The expected outcome is to receive a JSON array that can then be used to gather exchange rate data. Here is the link: http://www.google.com/ig/cal ...

Issue: Bidirectional binding functionality is not functioning properly within the user interface modal

I'm currently working on displaying data in a modal, but I'm facing issues with getting two-way binding to work properly. In my HTML code: <div class="cta-actions"> <div class="action"><a class="btn btn-lg btn-max">Send a pa ...

The request to sign up at 'https://identitytoolkit.googleapis.com/v1/accounts:/signUp? from the origin 'http://localhost:8080' has been denied

My attempt to create a new user in Firebase using Axios in Vue.js is resulting in an error message regarding CORS policy. The specific error states: "Access to XMLHttpRequest at 'https://identitytoolkit.googleapis.com/v1/accounts:/signUp?key=AIzaSyDvZ ...

navigation bar directing to the wrong destination

My landing page has attached pages like landing/gothere and /another. The issue arises when I try to navigate from /another to landing/gothere. I fetch landing information using an API, but there's a delay when I click on the navbar link. The page loa ...

Clicking the mouse within three.js

I'm facing an issue with my webpage that features a three.js (webgl) graphic created using a .dae file imported from Blender. My goal is to draw a square or mark wherever the mouse is clicked, but for some reason, the square appears in a different loc ...

Ways to clearly establish the concept of "a"

module.exports.getData = function (id) { const userData = require("./data/Users.json"); if (userData.find(user => user.uid === id)) { return user.name; } else return "User"; } I'm trying to display the name of a user, but the consol ...

What is the correct way to use variables to reference whether an item is odd or even in an ng-repeat loop?

Is there a way to access the variables $odd and $even within ng-repeat using a variable for reference? Here is what I have attempted: <ng-repeat="item in items" ng-if="$odd">these are odd{{item}}</div> <ng-repeat="item in items" ng-if="$eve ...