Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

73
Views
Saving array and objects within said array

I am trying to make a simple to do app using vue.js, I want to try and save my to-dos that are set in the array so that when I reset the site, they still remain. Looking through some of the documentation I arrived at this:

data() {
        return {
            array: [
                 {id: 1, label: 'learn vuejs'},
            ]
        }
    }, 
methods: {
        persist() {
            localStorage.array = this.array;
            alert('items saved')
        }
    },
mounted() {
        if (localStorage.array && localStorage.array.id) {
            this.array = localStorage.array;
            this.array[id] = localStorage.array.id;
        }
    },

while this does save my array to localStorage, IT DOES NOT THE OBJECTS WITHIN. When I check localStorage in the console it shows :

array: "[object Object]"

anyone knows how to save the items within the array? if you do please explain it to me.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to store them as string. So localStorage.array = JSON.stringify(this.array), and when fetching from localStorage this.array = JSON.parse(localStorage.array);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!