In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to achieve vue login graphics verification code, the article is very detailed, has a certain reference value, interested friends must read it!
The details are as follows
Effect picture:
Click on the pattern to switch characters
1. Create a new Identify.vue component
Export default {name: "identify", props: {identifyCode: {type: String, default:''}, fontSizeMin: {type: Number, default: 28}, fontSizeMax: {type: Number, default: 40}, backgroundColorMin: {type: Number, default: 180}, backgroundColorMax: {type: Number Default: 240}, colorMin: {type: Number, default: 50}, colorMax: {type: Number, default: 160}, lineColorMin: {type: Number, default: 40}, lineColorMax: {type: Number, default: 180}, dotColorMin: {type: Number, default: 0} DotColorMax: {type: Number, default: 255}, contentWidth: {type: Number, default: 130}, contentHeight: {type: Number, default: 40}}, methods: {/ / generate a random number randomNum (min, max) {return Math.floor (Math.random () * (max-min) + min)} / generate a random color randomColor (min, max) {let r = this.randomNum (min, max) let g = this.randomNum (min, max) let b = this.randomNum (min, max) return 'rgb (' + r +','+ g +','+ b +')'} DrawPic () {let canvas = document.getElementById ('smurcanvasa') let ctx = canvas.getContext ('2d') ctx.textBaseline =' bottom' / / drawing background ctx.fillStyle = this.randomColor (this.backgroundColorMin, this.backgroundColorMax) ctx.fillRect (0,0, this.contentWidth, this.contentHeight) / / drawing text for (let I = 0 I < this.identifyCode.length This.identifyCode +) {this.drawText (ctx, this.identifyCode [I], I)} this.drawLine (ctx) this.drawDot (ctx)}, drawText (ctx, txt, I) {ctx.fillStyle = this.randomColor (this.colorMin, this.colorMax) ctx.font = this.randomNum (this.fontSizeMin This.fontSizeMax) +'px SimHei' let x = (I + 1) * (this.contentWidth / (this.identifyCode.length + 1)) let y = this.randomNum (this.fontSizeMax, this.contentHeight-5) let deg = this.randomNum (- 30,30) / / modify coordinate origin and rotation angle ctx.translate (x, y) ctx.rotate (deg * Math.PI / 270) ctx.fillText (txt, 0 0) / / restore coordinate origin and rotation angle ctx.rotate (- deg * Math.PI / 270) ctx.translate (- x,-y)}, drawLine (ctx) {/ / draw interference line for (let I = 0) I < 2 ) {ctx.strokeStyle = this.randomColor (this.lineColorMin, this.lineColorMax) ctx.beginPath () ctx.moveTo (this.randomNum (0, this.contentWidth), this.randomNum (0, this.contentHeight)) ctx.lineTo (this.randomNum (0, this.contentWidth), this.randomNum (0) This.contentHeight)) ctx.stroke ()}, drawDot (ctx) {/ / drawing interference points for (let I = 0) I < 20 Ctx.fillStyle +) {ctx.fillStyle = this.randomColor (0255) ctx.beginPath () ctx.arc (this.randomNum (0, this.contentWidth), this.randomNum (0, this.contentHeight), 1, 0, 2 * Math.PI) ctx.fill ()} Watch: {identifyCode () {this.drawPic ()}}, mounted () {this.drawPic ()}} # s-canvas {height: 38px }
two。 Register for use with the parent component index.vue
Import Identify from'@ / components/test/identify'export default {name: "index", components: {Identify}, data () {return {identifyCode:', / / CAPTCHA Rule identifyCodes: '123456789ABCDEFGGKNPQRSTUVWXYZ,}}, methods: {/ / toggle CAPTCHA refreshCode () {this.identifyCode =' 'this.makeCode (this.identifyCodes) 4) console.log (this.identifyCode)}, / / generate random verification code makeCode (o, l) {for (let I = 0) I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.