Vue Vuetify 水平和垂直居中
Vue Vuetify center horizontally and vertically
我正在尝试将我的身份验证组件 (v-card) 水平和垂直居中。我尝试了各种解决方案,例如行上的 justify=center
和 align=center
,v-container 上的 fill-height,v-container 上的 class="fill-height"
但它不起作用。我在这里做错了什么?
代码:
<script setup lang="ts">
import { useUserStore } from "../../stores/user";
const store = useUserStore();
</script>
<template>
<v-card width="800" >
<v-card-title>
Authentication
</v-card-title>
<v-card-subtitle>
login with username and password
</v-card-subtitle>
<v-card-text>
<v-row>
<v-col cols="12" md="6">
<v-text-field v-model="store.username" label="Username"></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field v-model="store.password" label="Password"></v-text-field>
</v-col>
</v-row>
</v-card-text>
</v-card>
</template>
<script setup lang="ts">
import Auth from "../components/auth/Auth.component.vue"
</script>
<template>
<v-container>
<v-row style="border:1px solid red;" fill-height>
<v-col class="d-flex justify-center items-center">
<Auth/>
</v-col>
</v-row>
</v-container>
</template>
<template>
<v-app>
<v-main>
<router-view></router-view>
</v-main>
</v-app>
</template>
<script setup lang="ts">
</script>
更新
查看我制作的这个codesanbox:https://codesandbox.io/s/stack71483246-center-login-p1u6zv?file=/src/views/Home.vue
看起来只需将 class fill-height
添加到根容器就可以使其垂直居中。
<template>
<v-container fluid class="fill-height">
<v-row style="border:1px solid red;">
<v-col class="d-flex justify-center">
<Auth/>
</v-col>
</v-row>
</v-container>
</template>
我正在尝试将我的身份验证组件 (v-card) 水平和垂直居中。我尝试了各种解决方案,例如行上的 justify=center
和 align=center
,v-container 上的 fill-height,v-container 上的 class="fill-height"
但它不起作用。我在这里做错了什么?
代码:
<script setup lang="ts">
import { useUserStore } from "../../stores/user";
const store = useUserStore();
</script>
<template>
<v-card width="800" >
<v-card-title>
Authentication
</v-card-title>
<v-card-subtitle>
login with username and password
</v-card-subtitle>
<v-card-text>
<v-row>
<v-col cols="12" md="6">
<v-text-field v-model="store.username" label="Username"></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field v-model="store.password" label="Password"></v-text-field>
</v-col>
</v-row>
</v-card-text>
</v-card>
</template>
<script setup lang="ts">
import Auth from "../components/auth/Auth.component.vue"
</script>
<template>
<v-container>
<v-row style="border:1px solid red;" fill-height>
<v-col class="d-flex justify-center items-center">
<Auth/>
</v-col>
</v-row>
</v-container>
</template>
<template>
<v-app>
<v-main>
<router-view></router-view>
</v-main>
</v-app>
</template>
<script setup lang="ts">
</script>
更新
查看我制作的这个codesanbox:https://codesandbox.io/s/stack71483246-center-login-p1u6zv?file=/src/views/Home.vue
看起来只需将 class fill-height
添加到根容器就可以使其垂直居中。
<template>
<v-container fluid class="fill-height">
<v-row style="border:1px solid red;">
<v-col class="d-flex justify-center">
<Auth/>
</v-col>
</v-row>
</v-container>
</template>