この記事の例では、グラフィック検証コードを実装するための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 を設定する方法
1. 単一列インデックスどの列にインデックスを作成するかを選択することは、パフォーマンス最適化プロ...
この記事では、タブ切り替え効果を実現するためのJavaScriptの具体的なコードを参考までに紹介し...
1998 年の CSS2 勧告の時点で、テーブルは徐々に舞台から消え、歴史の中に記録されるようになり...
目次はじめにNginx Dockerファイル新しい会議もっと参考文献はじめに最近、アプリケーションの...
序文MySQL では、InnoDB はストレージ エンジン レイヤーに属し、プラグインとしてデータベ...
この記事では、MySQLのプリコンパイル機能について紹介します。具体的な内容は以下のとおりです。 1...
コードを見てみましょう:コードをコピーコードは次のとおりです。 < !DOCTYPE html...
中国語ドキュメント: https://router.vuejs.org/zh/ Vue Router...
序文パスワードを忘れることは、よく遭遇する問題です。MySQL または MariaDB データベース...
Openlayers は、WebGIS クライアント向けのモジュール式で高性能かつ機能豊富な Jav...
目次現象根本原因分析getLastPacketReceivedTimeMs() メソッドの呼び出し時...
この記事では、例を使用して、MySQL 累積集計の原理と使用方法を説明します。ご参考までに、詳細は以...
目次1. サンプルコード2. 現象を通して本質を見抜く3. 実施原則4. 親コンポーネントのコンパイ...
目次ステップ1. ルーティング ルールを設定し、子構成項目を使用します。 2. ジャンプ(フルパスを...
I. はじめにDockerテクノロジーは現在非常に人気があります。コンテナを介してプロジェクト環境を...