Problem:My <v-container>组件并不总是达到应用程序的高度.我试过使用fill-height属性,设置height: 100%;,设置height: 100vh;,甚至试过使用max-height.我似乎无法得到我想要的结果!

Goal:我希望我的容器始终横跨windows 的整个高度.我在应用程序上的主题在亮/暗之间变化.这会更改背景色,背景色应始终覆盖应用程序视图端口的整个高度和宽度.

Background not covering entire height

Code for 100:

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

推荐答案

所以对我来说,解决方案不仅是移除App.vue中的容器,还移除htmlbody<style scoped>标签的样式.我正在设置height: 100%;,这在动态加载内容时导致了一些问题.

正确的App.vue是这样的:

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

Vue.js相关问答推荐

如何用其他组件编译Vue模板?

VITE:无法为VUE单文件组件加载URL

Pinia+Vue 3状态react 性-StoreToRef的替代方案

vue 3 中范围样式和深度样式的问题

如果找不到路由,Vue.js如何重定向到公共路由

VuetifyJS,outer-link 未显示为光标

VueJS:为什么在input事件处理程序中触发Input输入事件?

如何使用带有自定义标签和类的`transition-group`

Webpack 你可能需要一个合适的加载器来处理这个文件类型

vuex 中 { dispatch, commit } 的类型是什么?

为什么不先移动鼠标就无法滚动视差?

如何在 vue 3 脚本设置中使用

如何在 Vue.js 中传递 $router.push 中的数据?

SassError:媒体查询表达式必须以(开头

我可以在 Vue 实例方法中传播的 mapMutations 中使用this吗?

使用 Spring Boot(VueJS 和 Axios 前端)禁止发布 403 帖子

无法访问手表处理程序 vuejs 中的数据变量

如何在布局中使用组件?

为什么 router.currentRoute.path 没有react?

在 Vue 中使用事件修饰符 .prevent 提交表单而不进行重定向