[Vuejs]-Add item to state after post in API get the id

0๐Ÿ‘

i seems there is an issue with the request. In my opinion, it should change to

     axios
       .post('http://127.0.0.1:8000/api/studies', addStudy)
       .then((result)=>{
               this.$store.commit("addStudie", {projet : this.newStudy.currentIdProject, study :result
        })
    })

if you have any problem place let me know

0๐Ÿ‘

You can save your ID in the localStorage that saves key value string data on the client side (browser)

addStudie(state , id) {
        // do somthing with state then save it into localStorage
        localStorage.setItem('myID', id);
    }

And a store getter that returns the id from localStorage

    theId(state) {
        const savedID = localStorage.getItem("myID")
        return savedID
    } 
if(theId()){
    // do something with your ID
}
else{
    // ID is not saved in the localStorage yet , call the API
    getDataFromAPI()
}

Leave a comment