2
0

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.

モバイルデバイスのときにだけボタンを表示させたい

Last updated at Posted at 2020-06-22

はじめに

Webアプリケーションを作っていると、モバイルデバイスのときだけNavigationBarのボタンを表示させたいということがよくあるので方法を紹介する。

なお前提としてUIフレームワークはVuetifyを使っているものとする。

制御にはBreakpointを使う

公式で紹介しているBreakpointを使うのが良い。

$vuetify.breakpoint という変数には現在の画面サイズに関する状態が保持されている。

スクリーンショット 2020-06-22 9.29.41.png

たくさんパラメーターがあるのでどれを使っても良いが、例えば xs を利用して制御を行うとこんな条件になる。

v-show="$vuetify.breakpoint.xs"

実際のソース上のではこんな感じ

<template>
  <v-app dark>
    <v-navigation-drawer
      v-model="drawer"
      :mini-variant="miniVariant"
      :clipped="clipped"
      fixed
      app
    >
      <v-list>
        <v-list-item
          v-for="(item, i) in items"
          :key="i"
          :to="item.to"
          router
          exact
        >
          <v-list-item-action>
            <v-icon>{{ item.icon }}</v-icon>
          </v-list-item-action>
          <v-list-item-content>
            <v-list-item-title v-text="item.title" />
          </v-list-item-content>
        </v-list-item>
      </v-list>
    </v-navigation-drawer>
    <v-app-bar :clipped-left="clipped" fixed app>
      <v-app-bar-nav-icon
        @click.stop="drawer = !drawer"
        v-show="$vuetify.breakpoint.xs"      <-------ここに一行追加
      />
      <v-spacer />
    </v-app-bar>
    <v-main>
      <v-container fluid>
        <nuxt />
      </v-container>
    </v-main>
    <v-footer :absolute="!fixed" app>
      <span>&copy; {{ new Date().getFullYear() }}</span>
    </v-footer>
  </v-app>
</template>

これで晴れてモバイルデバイスで表示している時のみメニューバーボタンが表示されるようになる。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?