目前只开发了H5端

第一步

在public/index.html的head中引入js文件

<script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>

第二步

在需要验证的页面生命周期mounted中写以下方法

mounted() {
	let self = this
	this.captcha1 = new TencentCaptcha('后端提供的appid', function(res) {
		console.log(res)
		if(res.ret === 0) {
            // 滑块滑动成功后的回调  Tendent函数为封装后的后端验证接口
		    Tendent(res.ticket, res.randstr).then(res=> {
				if(res.data.errcode === 0) {
					console.log('验证成功')
				}	
			})
		}
	});
},

第三步

在唤醒验证的按钮中绑定事件

<button @click="open"><button>

open () {
    this.captcha1.show();
}

是不是特别简单

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐