Vue3 チェックボックスの状態を取得するサンプル
構文
<input type="checkbox" @click="イベント名">
チェックボックスの状態を取得するには、「@click」を使用します。
使用例
チェックボックスにチェックの状態により、
テキストの表示・非表示を切り替えます。
サンプルコード
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>checkboxサンプル</title> <!-- semantic.css --> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"> <script src="https://unpkg.com/vue@next"></script> </head> <style> body>.grid { height: 100%; } .fields { margin-top: 5px; } </style> <body> <div id="app" class="ui middle aligned center aligned grid"> <div class="column"> <h2 v-show="flg">flg</h2> <div class="ui slider checkbox"> <input type="checkbox" @click="change" tabindex="0" checked> <label>checkbox</label> </div> </div> </div> <script> const cft = { data() { return { flg: true } }, methods: { change: function(e) { this.flg = e.target.checked } } } Vue.createApp(cft).mount('#app') </script> </body> </html>