hasyrails / calendar-vue-original

0 stars 0 forks source link

32 calendar multistep form / マルチステップフォームを実装 #54

Closed hasyrails closed 4 years ago

hasyrails commented 4 years ago

vue.jsでマルチステップの入力フォーム作成(基礎編)

hasyrails commented 4 years ago

入力項目は何にするか

1つ目のステップの入力フォームでは名前(firstName, lastName)を入力、2つ目のステップの入力フォームではEmail、電話番号を入力、3つ目は誕生日を入力するシンプルなものです。4つ目では1〜3で入力した項目の値を一括表示させます。

hasyrails commented 4 years ago

Registerコンポーネント内に実装していく

hasyrails commented 4 years ago

入力項目

data(){
    return{
      form: {
    userName: null,  //  ユーザー名
        email: null,  //  メールアドレス
        password: null, //  パスワード
        passwordConfirmation: null  //  パスワード確認
    }
 }
hasyrails commented 4 years ago

フォームに入力した値をformオブジェクトへ格納成功

Image from Gyazo

// Register.vue

<pre><code>{{form}}</code></pre>

でformオブジェクトの値を表示

hasyrails commented 4 years ago

ステップ移動を実装

Image from Gyazo

// Register.vue

<button class="btn btn-primary" @click="backStep" >Back</button>
<button class="btn btn-primary" @click="nextStep" >Next</button>

 methods:{
    backStep:function(){
          this.stepNumber--;
      },            
      nextStep:function(){
          this.stepNumber++;
      },
    }

STEP: 0, 4の時のボタン表示が不要

v-showで STEP:0,4の時非表示に変更

Image from Gyazo

// Register.vue

<button class="btn btn-primary" @click="backStep" v-show="stepNumber != 1">Back</button>
<button class="btn btn-primary" @click="nextStep" v-show="stepNumber != 4">Next</button>
hasyrails commented 4 years ago

3STEPフォーム入力 → 確認画面まで実装

Image from Gyazo