1.在public/index.html添加代码
<script src="https://www.recaptcha.net/recaptcha/api.js?render=explicit" async defer></script>
2.在使用页面添加一个标签挂在
<div id="grecaptcha"></div>
3.在data中创建siteKey(siteKey需要在谷歌申请)
sitekey: '6LdNKRsa********************',
4.在methods添加
getYzm (){
this.loaded()
}
loaded () {
setTimeout(() => {
window.grecaptcha.render('grecaptcha', {
sitekey: this.sitekey,
callback: this.submit
})
}, 200)
},
submit: async function (token) {
this.schizobuliaShow = false
this.countDown = true
const res = await sendSms({
token,
phone: this.phone,
code: this.areaCode
})
if (res.data.status === 200) {
Toast.success(res.data.message)
} else {
Toast.fail(res.data.message)
}
},