8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

コピペでどうぞ。Vuetifyを使用してログイン画面・新規登録画面を作成しました。

Posted at

概要

Vuetifyを用いて、「ログイン画面」・「新規登録画面」のUIを作成しました。
コード保存目的も兼ねて、記事にしておきます。
もし良ければ、コピペで使ってやって下さい。

作成した画面

ログイン画面
ログイン画面png.png
新規登録画面
新規登録画面.png

コード(ログイン画面)

<template>
  <v-card class="d-flex flex-column mx-auto my-6 flat" width="374" color="#fff">
    <v-card-title class="d-flex justify-center pa-0 mt-6"
      >ログイン</v-card-title
    >
    <v-card-text class="d-flex justify-center flex-column">
      <v-btn
        class="fill-width mt-6 text-capitalize caption mx-4"
        rounded
        color="#00ACEE"
        dark
        depressed
        height="48px"
        @click="submitTwitter"
      >
        <img
          class="button-logo-img mr-4"
          src="~/static/twitter.png"
          style="height: 20px"
        />
        twitterでログイン
      </v-btn>
      <v-btn
        class="fill-width mt-6 text-capitalize caption mx-4 mb-6"
        rounded
        height="48px"
        outlined
        style="border-color: #979797"
        @click="submitGoogle"
      >
        <img
          class="button-logo-img mr-4"
          src="https://madeby.google.com/static/images/google_g_logo.svg"
          style="height: 24px"
        />
        Googleでログイン
      </v-btn>
      <p class="text-center pt-3 mt-3 text-subtitle-1 siginIn-border-top">
        メールアドレスでログイン
      </p>
      <v-form class="mx-9" ref="form" v-model="valid">
        <v-text-field
          placeholder="メールアドレス"
          outlined
          dense
          :rules="mailRules"
        ></v-text-field>
        <v-text-field
          placeholder="パスワード"
          outlined
          dense
          :rules="pwRules"
        ></v-text-field>
        <p class="pointer" @click="forgetPw">パスワードを忘れた方</p>
        <div class="text-center">
          <v-btn class="primary" :disabled="!valid">ログイン</v-btn>
        </div>
      </v-form>
    </v-card-text>
  </v-card>
</template>

<script>
export default {
  data() {
    return {
      valid: false,
      mailRules: [
        (v) => !!v || "mail is required",
        v => /.+@.+\..+/.test(v) || 'E-mail must be valid',],
      pwRules: [(v) => !!v || "password is required"],
    };
  },
  methods: {
    validate() {
      this.$refs.form.validate();
    },
    submitTwitte() {
      // ツイッターログインの処理
    },
    submitGoogle() {
      // グーグルログインの処理
    },
    forgetPw() {
      // パスワードを忘れた時の処理
    },
  },
};
</script>

コード(新規登録)

<template>
<div>
  <v-card class="d-flex flex-column my-6 mx-auto" width="374" color="#fff">
    <v-form ref="form" v-model="valid">
      <v-card-title class="d-flex justify-center pa-0 mt-6 mb-3"
        >新規登録</v-card-title
      >
      <v-card-text class="d-flex justify-center flex-column">
        <div class="mx-9">
          <v-text-field
            label="ユーザー名"
            placeholder="15文字以内"
            outlined
            dense
            :rules="nameRules"
          ></v-text-field>
          <v-text-field
            label="メールアドレス"
            placeholder="mail@example.com"
            outlined
            dense
            :rules="mailRules"
          ></v-text-field>
          <v-text-field
            label="パスワード"
            placeholder="8文字以上の半角英数記号"
            outlined
            dense
            :rules="pwRules"
          ></v-text-field>
        </div>
        <div class="text-center">
          <v-btn class="primary" :disabled="!valid">登録</v-btn>
        </div>
        <p class="signUp-border-top text-center mt-6 mb-0 pt-6">
          ソーシャルアカウントでログイン
        </p>
        <v-btn
          class="fill-width mt-6 text-capitalize caption mx-4"
          rounded
          color="#00ACEE"
          dark
          depressed
          height="48px"
          @click="submitTwitter"
        >
          <img
            class="button-logo-img mr-4"
            src="~/static/twitter.png"
            style="height: 20px"
          />
          twitterでログイン
        </v-btn>
        <v-btn
          class="fill-width mt-6 text-capitalize caption mx-4 mb-6"
          rounded
          height="48px"
          outlined
          style="border-color: #979797"
          @click="submitGoogle"
        >
          <img
            class="button-logo-img mr-4"
            src="https://madeby.google.com/static/images/google_g_logo.svg"
            style="height: 24px"
          />
          Googleでログイン
        </v-btn>
      </v-card-text>
    </v-form>
  </v-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      valid: false,
      nameRules: [
        (v) => !!v || "user name is required",
        (v) => (v && v.length <= 15) || "最大15文字です。",
      ],
      mailRules: [
        (v) => !!v || "mail is required",
        v => /.+@.+\..+/.test(v) || 'E-mail must be valid',],
      pwRules: [(v) => !!v || "password is required"],
    };
  },
  methods: {
    validate() {
      this.$refs.form.validate();
    },
    submitTwitter() {
      // ツイッターログインの処理
    },
    submitGoogle() {
      // グーグルログインの処理
    },
  },
};
</script>

補足

Twitterのアイコン画像は、公式サイトからダウンロードして下さい。
Twitterロゴ

facebookが必要ならこちらから

facebookのログインも必要な場合は、下記コードをご使用下さい。

<v-btn
   class="fill-width mt-6 text-capitalize caption mx-4"
   color="#3B5998"
   rounded
   dark
   depressed
   height="48px"
   @click="submitFacebook"
>
  <img
    class="button-logo-img mr-4"
    src="~/static/f_logo_RGB-White_1024.png"
    style="height: 24px"
  />
    Facebookでログイン
</v-btn>

facebookロゴ

最後に

ルール等は、適宜修正してご使用下さい。
不明点、誤りがある場合、お手数ですがコメントにてお知らせ下さい。

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?