MENU

小程序开发之随机验证码功能

January 17, 2020 • javascript

//验证码
createCode() {
  let vCode = '';
  let vCodeLength = 4;//限制位数
  let random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  for (let i = 0; i < vCodeLength; i++) {
    let index = Math.floor(Math.random() * 10);
    vCode += random[index];
  }
  this.setData({
    vCode: vCode
  })
},
转载请注明出处,并添加原文地址

Archives QR Code Tip
QR Code for this page
Tipping QR Code