この記事の例では、グラフィック検証コードを実装するためのVueの具体的なコードを参考までに共有しています。具体的な内容は次のとおりです。 効果画像:または または または コード:検証コードのコンポーネント: src/common/sIdentify.vue <テンプレート> <div class="s-canvas"> <canvas id="s-canvas" :width="contentWidth" :height="contentHeight"></canvas> </div> </テンプレート> <スクリプト> エクスポートデフォルト{ 名前: 'SIdentify', 小道具: { 識別コード: タイプ: 文字列、 デフォルト: '1234' }, フォントサイズ最小: { タイプ: 数値、 デフォルト: 18 }, フォントサイズ最大: { タイプ: 数値、 デフォルト: 40 }, 背景色最小: { タイプ: 数値、 デフォルト: 180 }, 背景色最大: { タイプ: 数値、 デフォルト: 240 }, 色最小: タイプ: 数値、 デフォルト: 50 }, 色最大値: { タイプ: 数値、 デフォルト: 160 }, ラインカラー最小: { タイプ: 数値、 デフォルト: 40 }, ラインカラー最大: { タイプ: 数値、 デフォルト: 180 }, ドットカラー最小: { タイプ: 数値、 デフォルト: 0 }, ドットカラーマックス: { タイプ: 数値、 デフォルト: 255 }, コンテンツ幅: { タイプ: 数値、 デフォルト: 111 }, コンテンツの高さ: { タイプ: 数値、 デフォルト: 38 } }, メソッド: { // 乱数を生成する randomNum(min, max) { Math.floor(Math.random() * (max - min) + min) を返します。 }, // ランダムな色を生成する randomColor(min, max) { r = this.randomNum(最小値, 最大値) とします。 g = this.randomNum(min, max) とします。 b = this.randomNum(最小値, 最大値) とします。 'rgb(' + r + ',' + g + ',' + b + ')' を返します }, 描画画像() { キャンバス = document.getElementById('s-canvas') とします。 ctx = canvas.getContext('2d') とします。 ctx.textBaseline = '下' // 背景を描画します ctx.fillStyle = this.randomColor(this.backgroundColorMin, this.backgroundColorMax) ctx.fillRect(0, 0, this.contentWidth, this.contentHeight) // テキストを描画する for (let i = 0; i < this.identifyCode.length; i++) { 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' x = (i + 1) * (this.contentWidth / (this.identifyCode.length + 1)) とします。 y = this.randomNum(this.fontSizeMax, this.contentHeight - 5) とします。 var deg = this.randomNum(-30, 30) // 文字の回転角度(45度以下が望ましい) // 座標原点と回転角度を変更する ctx.translate(x, y) ctx.rotate(度 * Math.PI / 180) です。 ctx.fillText(txt, 0, 0) // 座標原点と回転角度を復元します ctx.rotate(-deg * Math.PI / 180) ctx.translate(-x, -y) }, 描画線(ctx) { // 干渉線を描く for (let i = 0; i < 8; i++) { 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.ストローク() } }, 描画ドット(ctx) { // 干渉点を描画する for (let i = 0; i < 100; i++) { ctx.fillStyle = this.randomColor(0, 255) ctx.beginPath() ctx.arc(this.randomNum(0, this.contentWidth), this.randomNum(0, this.contentHeight), 1, 0, 2 * Math.PI) ctx.fill() } } }, 時計: 識別コード() { この.drawPic() } }, マウント() { この.drawPic() } } </スクリプト> 親コンポーネント <テンプレート> <div> <div>検証コードテスト</div> <div @click="refreshCode()" class="code" style="cursor:pointer;" title="クリックして確認コードを切り替えます"> <s-identify :identifyCode="identifyCode"></s-identify> </div> </div> </テンプレート> <スクリプト> 'vue' から defineComponent をインポートします。 "@/common/sIdentify.vue" から sIdentify をインポートします。 // 'axios' から axios をインポート エクスポートデフォルトdefineComponent({ 名前: 'WatermarkTest'、 コンポーネント: { sIdentify }, データ() { 戻る { 識別コード: "", identifyCodes: ['0','1','2','3','4','5','6','7','8','9','a','b','c','d'], //実際のニーズに応じて必要な文字を追加します} }, マウント() { this.refreshCode() }, アンマウント() { }, メソッド: { // 乱数を生成する randomNum(min, max) { 最大値 = 最大値 + 1 Math.floor(Math.random() * (max - min) + min) を返します。 }, // 検証コードを更新する refreshCode() { this.identifyCode = ""; this.makeCode(this.identifyCodes, 4); console.log('現在の検証コード:',this.identifyCode); }, // 検証コードをランダムに生成する string makeCode(data, len) { console.log('データ, 長さ:', データ, 長さ) (i = 0; i < len; i++) の場合 { this.identifyCode += this.identifyCodes[this.randomNum(0, this.identifyCodes.length-1)] } }, }, }); </スクリプト> 以上がこの記事の全内容です。皆様の勉強のお役に立てれば幸いです。また、123WORDPRESS.COM を応援していただければ幸いです。 以下もご興味があるかもしれません:
|
>>: 画像の盗難を防ぐために Nginx で Referer を設定する方法
docker run後、ステータスは常にExitedになります解決:パラメータを追加: -it do...
多くの場合、移行は避けられません。ハードウェアのアップグレード、データ センターの変更、古いオペレー...
概要データベースは通常、複数のトランザクションを同時に実行します。複数のトランザクションが、同じデー...
目次1. データソース2. データの総合順位1) 総合ランキング2) 同順位3) 同順位3. データ...
Linux の seq コマンドは、数字のリストを非常に高速に生成でき、使いやすく柔軟性に優れてい...
序文ミニプログラムのアップロードには https が必要なので、サーバーの https は lets...
目次メイントピック1. UbuntuにDockerをインストールする2. DockerにROS2-F...
1. ダウンロードしたMySQLの圧縮パッケージをインストールディレクトリに解凍します。 2. 新し...
JD カルーセルは、動的な効果を追加せず、主に位置決めの知識を使用して、純粋な HTML と CS...
この記事では、3D テキストのホバー変更効果を実現するための CSS3 のサンプル コードを紹介しま...
1. Apacheをインストールする # yum インストール -y httpd httpd-de...
目次導入js のイテレータはどのように見えるか反復プロトコル反復可能なプロトコルイテレータプロトコル...
結果:実装コード: <!DOCTYPE html><html class=&quo...
序文 [root@localhost ~]# cat /etc/fstab # #/etc/fsta...
私が実現したい機能は、新しいウィンドウを開いて新しいページを表示することですが、パラメータを渡す必要...