After a page refresh, the Vuex state ends up being null within the mutation rather than the expected predefined

When developing a basic application, I set up a series of mutations and actions linked to the component creation hook. However, upon refreshing the browser using F5 and accessing vue-devtools on the Vuex tab, an unexpected error occurs at the beginning of the application startup.

The main issue at hand is why the state is showing as 'null' and how this can be rectified.

store.js

export default new Vuex.Store({
  state: {
    x: null,
    y: null
  },
  mutations: {
    SET_X (state, x) {
      console.info(x)
      state.x = x
    },
    SET_Y (state, y) {
      state.y = y
    }
  },
  actions: {
    setX ({ commit }, x) {
      console.info(x)
      commit('SET_X', x)
    },
    setY ({ commit }, y) {
      commit('SET_Y', y)
    }
  }
})

Home.vue

<script>
// @ refers to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  name: 'home',
  components: {
    HelloWorld
  },
  created: function () {
    this.$store.dispatch('setX', 'X')
  }
}
</script>

About.vue

<script>
export default {
  name: 'about',
  components: {
  },
  created: function () {
    this.$store.dispatch('setY', 'Y')
  }
}
</script>

Console log in the Components tab

log.js?1afd:24 [HMR] Waiting for update signal from WDS...
store.js?c0d6:22 X
store.js?c0d6:13 Y
backend.js:1585  vue-devtools  Detected Vue v2.6.10 

Console log in the Vuex tab

log.js?1afd:24 [HMR] Waiting for update signal from WDS...
store.js?c0d6:22 X
store.js?c0d6:13 Y
backend.js:1585  vue-devtools  Detected Vue v2.6.10 

store.js?c0d6:13 null

backend.js:14674 Uncaught TypeError: Cannot set property 'x' of null
    at Store.SET_X (store.js?c0d6:14)
    at wrappedMutationHandler (vuex.esm.js?2ba1:725)
    at backend.js:14664
    ...

Answer №1

Under the devtools settings, I found the solution in selecting "New Vuex backend."

Although I'm not sure why, disabling this option resolved the issue I was facing.

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

Does Three.js lighting adjust according to the bundler used?

Today, I decided to streamline my portfolio project by transitioning it from standard HTML to the Vite bundler for easier dependency management. I simply copied and pasted the existing code, making adjustments to the imports since I had been using relative ...

Manipulating arrays within Vuejs does not trigger a re-render of table rows

I have successfully generated a user table using data retrieved from an ajax request. The table has a structure similar to this: [Image of Table][1] Now, when an admin makes changes to a user's username, I want the respective row to update with the n ...

Converting an object to a string and then back to an object in ECMAScript 6Serialization and deserialization in ECM

One of the new features in ES6 (ECMAScript 6) is the introduction of the 'class' keyword. Here's an example of how a class can be defined: class MyClass { constructor() { this.MyProperty = 0; } } var obj = new MyClass(); co ...

Can you explain the distinction between the views and components directories within a Vue project?

After using the command line (CLI) to set up a Vue.js project, I noticed that the CLI automatically created both a src/components and src/views folder. It has been quite some time since I last worked on a Vue project, so this folder structure is unfamilia ...

Voxel world culling: The art of selection

In the realm of my imagination lies a world filled with voxels, measuring at 320*320*96 in size. My vision is to load this expansive world directly into the memory of my graphics card in order to avoid any loss in performance while transferring new "chunks ...

TS1343: Usage of the 'import.meta' meta-property is restricted to when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext' mode

Whenever I attempt to compile my project into esm and cjs, I encounter this error consistently. This is the content of my package.json: { "name": "qa-data-tool", "version": "1.0.0", "descript ...

Looking to include a new item into an array with the help of AngularJS

Having just started with angularJS, I am facing difficulties in adding an object from a form to an array. When I click on "Add New Product", it triggers the "newItemModal". I enter the new product information but the submit button doesn't seem to work ...

New and Improved React Material Collapse with onClick Event [Answer Refreshed]

I am currently working on a component that contains a list of details. Each item in the list has a "Details" button, and when clicked, it should show additional information only for that specific item. I am using Material-Ui with React and have imported ...

Hide button for the last input form to dynamically remove in jQuery

At first, I hide the remove button when there is only one form. However, if there are multiple forms and the user deletes all of them, I want the last form to remain visible and not be deleted. Can someone assist with this issue? Here is my code: <! ...

Connect or disconnect an element to a JavaScript event handler using an anonymous function

I'm stuck on a basic issue... I have a custom metabox in my WordPress blog, and here's my event handler: jQuery('tr input.test').on('click', function( event ){ event.preventDefault(); var index = jQuery(this).close ...

Providing properties to the main Vue.js components

An Issue I'm Facing I am currently attempting to pass a prop to my root constructor. To achieve this, I have been exploring the use of propsData, which I learned about from this resource: var appComponent = Vue.component('app', require(&ap ...

JavaScript code altered link to redirect to previous link

I added a date field to my HTML form. <input type="date" name="match_date" id="matchDate" onchange="filterMatchByDate(event)" min="2021-01-01" max="2021-12-31"> There is also an anchor tag ...

Sharing an array between two sibling components

Within my 'Home' component, users have the ability to create QR codes. I have implemented a method that generates an array of these QR items. Now, the challenge lies in passing this array to another component that is a sibling and not located wit ...

Two objects intersecting in space

When using AngularJS for insert and update operations, I encounter a problem where changes made to user data are reflected in the list of users. Additionally, when adding a new user, the last record's data populates all input fields. Code: User List ...

Exploring the world of AngularJS with nested JSON structures and utilizing ng-repeat

While going through code left behind by a previous team member, I find myself navigating the transition to Angular solo, without anyone around to brainstorm with. This brings me to my question for the community. I am working with JSON data that contains t ...

The submit function in Jquery is not functioning properly within the success callback of an Ajax request

After successfully submitting a form in AJAX using POST, I receive a new form that needs to be automatically submitted in jQuery. However, for some reason, the .submit() function seems to be ignored and I can't figure out why. I've tried adding ...

What's the best way to save data from an HTML input field into a JavaScript array?

Can someone help me with storing a value from an HTML input field into a JavaScript array after a button click, and then displaying that array data on the screen? Here is the HTML code I am currently working with: <!DOCTYPE HTML> <html> < ...

Form submission is not possible while the login form is active

I'm encountering an issue where I am unable to trigger - ng-submit or ng-click on this code except for the local onclick function on the login button. If you have any insights or solutions, please share them: <form ng-submit = "login.submitLogin ...

Issue with calling jqPlot function in jQuery causing malfunction

I am perplexed as to why the initial code functions correctly while the second code does not. <a data-role="button" href="#page2" type="button" onClick="drawChart([[["Test1",6],["Test2",5],["Test3",2]]])"> <img src="icons/page2.png" inline style ...

Is it possible to automatically play a sound clip when the page loads?

Is there a way to automatically play a sound clip when my page loads? Are there any specific JavaScript or jQuery methods I can use for this, as I am developing my page using PHP. ...