Skip to content

Instantly share code, notes, and snippets.

@c0depanda
Created Jun 19, 2017
Embed
What would you like to do?
Method for creating a unique reference number
<template>
<div>
<p>Reference Number: {{referenceNumber}}
</div>
</template>
<script>
export default {
data: function () {
return {
referenceNumber: ''
}
},
created () {
this.refNumber();
}
methods: {
refNumber: function () {
let length = 12
let timestamp = new Date().getTime();
let _getRandInt = function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
let generate = function () {
let ts = timestamp.toString();
let parts = ts.split('').reverse();
let ref = '';
for (let i = 0; i < length; ++i) {
let index = _getRandInt(0, parts.length - 1);
ref += parts[index];
}
return ref;
}
this.referenceNumber = generate();
},
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment