I built my first ever app with the Vue-cli the best part of a year ago and I've been going through my repos and there wre a couple of things I've wanted to add it but I'm not sure how.
The working example is here and git repo
I have it setup to add an new example to the list, but whnever you refresh the page it removes the newly added items. Is there a way to use localStorage (or something else?) to be to store these when you refresh the page? I did attempt to add localStorage using the example found in the docs, but it didn't work so I'm doing something wrong I'm not sure what.
Also is there a way to have a sort of console and actually run the code I've set out in the examples?
Any help or suggestions most appreciated.
Top comments (6)
Not sure if localStorage is truly what you want here as it is indeed local. So when you add an item on your PC, you won't be able to see it on your phone, etc.
Here's how a simple localStorage implementation could look like in this file: github.com/cguttweb/array-helper/b...
arrayMethods
Inside
data()
retrieve the added items (or default it to an empty array), then add it toarrayMethods
addMethod()
, set the localStorage:Thanks for the reply I was attempting something similar but I think I just missed a step. I wasn't sure about LS if not LS then Vuex? Is there an alternative? I'm still pretty much a beginner to lot of this stuff so open to any suggestions.
It really depends on your use case. But if you want to persist data so that, when one user adds a method, every person on the internet should see it too, then vuex won't help here either. It is just a way to manage your local state.
In such a case, what you actually want is to persist the data in a database like MySQL (requires server) or maybe something serverless like Firebase. Firebase is probably easier to set up as you don't need to host the database yourself somewhere and there is a free tier that should be good enough.
I've read a bit on Firebase I will take a look and give it a go thanks :)
Thanks for the reply. I did try saving to LS but it didn't work so I think I deleted it.. i was attempting to do something like this
which is based on the example given in the docs here but I think I was just doing it wrong. I've used localStorage before but not with Vue so not sure if I'm just missinga step somewhere.
I thought about Vuex but 1. I don't really understand it (I've tried and failed) and 2. I thought it might be overkill for a fairly small project like this but I amy well be wrong.