[Vuejs]-Generate random string for dynamic input in vuejs

2πŸ‘

βœ…

It does not make much sense returning things on event handlers. It would be better in my opinion to pass the whole object and modify it, as follow:

<div v-show="id" v-for="(entry, index) in model.$.tokens" :key="'current' + index">
   <input type="text" v-model="entry.title">
   <input type="text" v-model="entry.token">
   <button type="button" @click="generate(entry)">Generate random token</button>
</div>
generate(entry) {
  entry.token = Math.random().toString(36).slice(2);
}

0πŸ‘

Your passing and returning value

generate(payload) {
  token = String(payload) + Math.random().toString(36).slice(2);
  return token;
}

Leave a comment