如何在 Vuetify 中水平对齐 v-col?

4
我希望将这七个按钮居中对齐。如您所见,最后一个按钮与第一个按钮相比有点偏移。

enter image description here

我该如何实现这个?我已经尝试了 justify="center"justify="space-around" 这是我的代码:
  <v-row no-gutters justify="space-around">
    <v-col v-for="(item, index) in buttons" :key="index">
      <toggle-button
        :weekday="item.weekday"
        :button="item.state"
      ></toggle-button>
    </v-col>
  </v-row>

这是toggle-button组件:
<template>
  <v-btn
    outlined
    depressed
    :class="button ? 'primary white--text' : 'outlined'"
    @click="button ? (button = false) : (button = true)"
    v-model="button"
    icon
  >
    {{ $t("roomservice.weekdays." + weekday) }}
  </v-btn>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: ["button", "weekday"]
};
</script>
1个回答

18

v-col不是一个弹性容器,内部的内容(toggle-button)默认从左侧对齐。

您可以通过在 v-col 上添加 class="d-flex justify-center" 来解决此问题。

<v-row no-gutters justify="space-around">
    <v-col 
        class="d-flex justify-center"
        v-for="(item, index) in buttons" 
        :key="index">
        <toggle-button
            :weekday="item.weekday"
            :button="item.state"
        ></toggle-button>
    </v-col>
</v-row>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接