vue項目中經常遇到for循環需要唯一key的問題,一直都是用的index,沒想到實戰項目裏面爆了,因爲嵌套循環導致key重複了,所以有了這個方法。
/**
* 生成一個用不重複的ID
* @param { Number } randomLength
*/
function getUuiD(randomLength){
return Number(Math.random().toString().substr(2,randomLength) + Date.now()).toString(36)
}