uni-app小程序、微信小程序,js、页面生成随机短信验证码
话不多说,直接上代码
/**
* 生成随机验证码
*/
getSortCode:function() {
let code='';
for (var i = 0; i < 6; i++) {
//获取0-9的随机整数
let randomNum=parseInt(Math.floor(Math.random()*10));
//把随机整数拼接成字符串(验证码)
code+=randomNum+'';
}
console.log(code)
},
然后就可以使用验证码进行操作了