web-dev-qa-db-fra.com

Le conteneur Vuetify ne remplit pas la hauteur

Problème : Mon <v-container> le composant ne va pas toujours à la hauteur de l'application. J'ai essayé d'utiliser la propriété fill-height , définissant height: 100%;, réglage height: 100vh;, a même essayé d'utiliser max-height. Je n'arrive pas à obtenir les résultats que je veux!

Objectif : Je veux que mon conteneur couvre toujours toute la hauteur de la fenêtre. Mon thème sur l'application change entre clair/foncé. Cela change la couleur d'arrière-plan, qui doit toujours couvrir toute la hauteur et la largeur du port de vue d'application.

Background not covering entire heightShowing container not spanning entire height

Code pour App.vue:

<template>
  <v-app>
    <main>
      <v-container
        fluid
        fill-height
        id="app"
        tag="div"
        style="height: 100vh; max-height: 100%;"
        :class="theme"
      >
        <Toolbar color="primary" />
        <transition
          name="routerAnimation"
          enter-active-class="animated faster fadeIn"
        >
          <router-view></router-view>
        </transition>
        <v-snackbar
          :color="alertColor"
          class="animated faster heartBeat"
          :dark="isDark"
          v-model="alert"
          :multi-line="mode === 'multi-line'"
          :timeout="alertTimeout"
          top
          :vertical="mode === 'vertical'"
        >
          <v-icon class="pr-4">{{ getAlertIcon() }}</v-icon>
          {{ alertMessage }}
          <v-btn :dark="isDark" icon @click="toggleAlert(false)">
            <v-icon>close</v-icon>
          </v-btn>
        </v-snackbar>
      </v-container>
    </main>
  </v-app>
</template>

<script>
import Toolbar from "./components/Toolbar";
import { themeMixin } from "./mixins/themeMixin.js";
import { alertMixin } from "./mixins/alertMixin";
import { authMixin } from "./mixins/authMixin";
import { socketMixin } from "./mixins/socketMixin";
import { TokenService } from "./services/tokenService";
import { ThemeService } from "./services/themeService";
import { UserService } from "./services/userService";
import { cordMixin } from "./mixins/cordMixin";

export default {
  name: "app",
  mixins: [alertMixin, authMixin, cordMixin, themeMixin, socketMixin],
  components: { Toolbar },
  created() {
    this.init();
    const theme = ThemeService.getTheme();

    if (theme !== null) {
      this.$store.commit("theme", theme);
    } else {
      this.$store.commit("theme", this.isDark ? "dark" : "light");
    }
  },
  data() {
    return {
      color: "#0c0c0c",
      y: "top",
      x: null,
      mode: ""
    };
  },
  mounted() {
    this.init();
  }
};
</script>

<style>
@import "https://cdn.materialdesignicons.com/2.5.94/css/materialdesignicons.min.css";
@import "https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons";

html {
  height: 100%;
}
body {
  height: 100%;
  margin: 0 auto 0;
}
#app {
  height: 100%;
  font-family: "Hilda-Regular", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.page {
  width: inherit;
}
</style>

5
Evan Bechtol

La solution pour moi était donc non seulement de retirer le conteneur dans App.vue, mais aussi pour supprimer les styles du <style scoped> tag pour html et body. Je mettais le height: 100%;, ce qui a causé certains problèmes lors du chargement dynamique du contenu.

La bonne App.vue ressemble à ça:

<template>
  <v-app id="app" :dark="isDark">
    <Toolbar color="primary" />
    <transition
      name="routerAnimation"
      enter-active-class="animated faster fadeIn"
    >
      <router-view></router-view>
    </transition>
    <v-snackbar
      :color="alertColor"
      class="animated faster heartBeat"
      :dark="isDark"
      v-model="alert"
      :multi-line="mode === 'multi-line'"
      :timeout="alertTimeout"
      top
      :vertical="mode === 'vertical'"
    >
      <v-icon class="pr-4">{{ getAlertIcon() }}</v-icon>
      {{ alertMessage }}
      <v-btn :dark="isDark" icon @click="toggleAlert(false)">
        <v-icon>close</v-icon>
      </v-btn>
    </v-snackbar>
  </v-app>
</template>

<script>
import { themeMixin } from "./mixins/themeMixin.js";
import Toolbar from "./components/Toolbar";
import { alertMixin } from "./mixins/alertMixin";
import { authMixin } from "./mixins/authMixin";
import { socketMixin } from "./mixins/socketMixin";
import { TokenService } from "./services/tokenService";
import { ThemeService } from "./services/themeService";
import { UserService } from "./services/userService";
import { cordMixin } from "./mixins/cordMixin";

export default {
  name: "app",
  mixins: [alertMixin, authMixin, cordMixin, themeMixin, socketMixin],
  components: { Toolbar },
  created() {
    this.init();
    const theme = ThemeService.getTheme();

    if (theme !== null) {
      this.$store.commit("theme", theme);
    } else {
      this.$store.commit("theme", this.isDark ? "dark" : "light");
    }
  },
  data() {
    return {
      color: "#0c0c0c",
      y: "top",
      x: null,
      mode: ""
    };
  },
  methods: {
    init() {
      const token = TokenService.getToken();
      const user = UserService.getUser();

      if (token) {
        this.$store.commit("token", token);
        this.setExpiry();
      }

      if (user) {
        this.$store.commit("user", JSON.parse(user));
      }
    }
  },
  mounted() {
    this.init();
  },
  watch: {}
};
</script>

<style>
@import "https://cdn.materialdesignicons.com/2.5.94/css/materialdesignicons.min.css";
@import "https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons";

#app {
  font-family: "Hilda-Regular", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>

1
Evan Bechtol