0

I have inside my vuex store a function to create a post. And the function returns a json Object with a unique uuid from uuidv4(). But if I run the function two times (or more) I get the same uuid and that's a problem. (Only if I reload the page I get a new uuid).

// store.js
import uuidv4 from 'uuid/v4';
var uuid = uuidv4();
const state = {
  postDetails: {
    ...
    uuid:  uuid,
    ...
  }
}

const actions = {
  post ({state}) {
    var postArray = []
    postArray.push(state.postDetails)
    // some axios stuff...
  }
}

So everything works fine. The main problem is the uuid which doesn't change after the function is called.

I use vuex-persistedstate also

1 Answers1

0

for those who need this

Solved my problem. I have added a function which creates a uuid without page reload.

function uuidv44() {
  return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  )
}

With help from this site Create GUID / UUID in JavaScript?