vue驗(yàn)證碼組件使用方法詳解
本文實(shí)例為大家分享了vue驗(yàn)證碼組件使用的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
代碼如下:
<template> <div class='join_formitem'> <label class='enquiry'>驗(yàn)證碼<span>:</span></label> <div class='captcha'> <input type='text' placeholder='請(qǐng)輸入驗(yàn)證碼' v-model='picLyanzhengma' /> <input type='button' @click='createdCode' v-model='checkCode' /> </div> </div></template><script>export default { data(){ return{ code:’’, checkCode:’’, picLyanzhengma:’’ //..驗(yàn)證碼圖片 } }, created(){ this.createdCode() }, methods: { // 圖片驗(yàn)證碼 createdCode(){ // 先清空驗(yàn)證碼輸入 this.code = '' this.checkCode = '' this.picLyanzhengma = '' // 驗(yàn)證碼長(zhǎng)度 const codeLength = 4 // 隨機(jī)數(shù) const random = new Array(0,1,2,3,4,5,6,7,8,9,’A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’) for(let i = 0;i < codeLength;i++){// 取得隨機(jī)數(shù)的索引(0~35)let index = Math.floor(Math.random() * 36)// 根據(jù)索引取得隨機(jī)數(shù)加到code上this.code += random[index] } // 把code值賦給驗(yàn)證碼 this.checkCode = this.code } }}</script><style>.yanzhengma_input{ font-family: ’Exo 2’,sans-serif; border: 1px solid #fff; color: #fff; outline: none; border-radius: 12px; letter-spacing: 1px; font-size: 17px; font-weight: normal; background-color: rgba(82,56,76,.15); padding: 5px 0 5px 10px; margin-left: 30px; height: 30px; margin-top: 25px; border: 1px solid #e6e6e6;}.verification{ border-radius: 12px; width: 100px; letter-spacing: 5px; margin-left: 50px; height: 40px; transform: translate(-15px,0);}.captcha{ height:50px; text-align: justify;}</style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于javascript處理二進(jìn)制圖片流過(guò)程詳解2. JS sort方法基于數(shù)組對(duì)象屬性值排序3. ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作。”的詭異問(wèn)題……4. JAVA上加密算法的實(shí)現(xiàn)用例5. Django-migrate報(bào)錯(cuò)問(wèn)題解決方案6. ajax請(qǐng)求添加自定義header參數(shù)代碼7. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)8. Gitlab CI-CD自動(dòng)化部署SpringBoot項(xiàng)目的方法步驟9. 使用Python和百度語(yǔ)音識(shí)別生成視頻字幕的實(shí)現(xiàn)10. 淺談SpringMVC jsp前臺(tái)獲取參數(shù)的方式 EL表達(dá)式
