PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 16, 2022

[FIXED] why is this Vuex state syntax throwing error?

 October 16, 2022     frontend, javascript, vue.js, vuex     No comments   

Issue

I'm quite new with Vuejs & Vuex, I created a local project just to practice, so I have a file called: employeeList with an Array of objects. I'm trying to pass that same Array as state in Vuex, but is throwing me errors. I assume the syntax is wrong, please tell what would be the correct approach and if the problem is in fact the syntax. Thank you & here's the code :

export const employeesModule = {
    namespaced: true,
    state : {
        [
            {
            id: 1, 
            name:'Terry Lawrence',
            username:'TerryLaw',
            email: 'TerryLaw@gmail.com',
            address: 'whateverStreet 258',
            checked: checked.value
            },
            {
            id: 2, 
            name:'MartyClFly',
            username:'MartyMac',
            email: 'MartyMac@gmail.com',
            address: 'George Junior 300',
            checked: checked.value
            },
            {
            id: 3, 
            name:'Nancy Pelosi',
            username:'Drunk ho',
            email: 'drunkHo@gmail.com',
            address: 'Velbedere 400',
            checked: checked.value
            }
]
            
    }, 

The actual file is longer, but there's no purpose to add the mutations, actions, etc...


Solution

Your syntax is wrong on your object "state". If you want it to be an object that contains an array, you need to set it a value like so:

state: {
  newArray: [...]
}

You can't just have an object that contains an array and is not set with a key.



Answered By - Jet.B.Pope
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing