如何将内容与Vuetify中v卡组件的中心对齐?

Iss*_*aki 7 vue.js vuetify.js

当前在products.vue中,我有一个productList数组,其中包含4个对象。我将遍历数组,并将每个单独的对象传递给ProductsItem.vue组件。在该组件中,我使用vuetify创建卡。

我无法将内容对准卡的中心。

这是我的代码,我的卡片的屏幕截图以及所需的结果

产品.vue

    <template>
      <div>
        <h1>Products</h1>
        <v-container class="my-5">
          <v-layout row wrap>
            <v-flex xs12 sm6 md4 v-for="productItem in productList" 
    :key="productItem.id">
              <ProductItems :productItem="productItem"/>
            </v-flex>
          </v-layout>
        </v-container>
      </div>
    </template>

    <script>
    import ProductItems from "@/components/ProductItems";


    export default {
      data() {
        return {
          productList: [
            {
              id: 1,
              name: "Superdry",
              description: "Rookie Aviator Patched Bomber"
            },
            {
              id: 2,
              name: "SuperHot",
              description: "Rookie Aviator Patched Bomber"
            },
            {
              id: 3,
              name: "Buron MensWear",
              description: "Skinny Fit Oxford Shirt In White"
            },
            {
              id: 4,
              name: "Asos",
              description: "slim shirt with stretch in blue"
            }
          ]
        };
      },

        components: {
          ProductItems
        }
      }
    </script>
Run Code Online (Sandbox Code Playgroud)

ProductItem.vue

    <template>
      <v-card flat class="ma-3 text-xs-center">
      <v-img src="https://cdn.vuetifyjs.com/images/cards/desert.jpg" aspect- 
    ratio="2.75"></v-img>
        <v-card-title primary-title>
          <div>
            <h3 class="headline pink--text text--accent-2"> 
    {{productItem.name}}</h3>
            <div>{{productItem.description}}</div>
          </div>
        </v-card-title>
        <v-card-actions>
          <v-btn flat color="orange">Add to Cart</v-btn>
        </v-card-actions>
      </v-card>
    </template>

    <script>
    export default {
      props: ["productItem"],
      data() {
        return {};
      }
    };
    </script>

<style>
</style>
Run Code Online (Sandbox Code Playgroud)

当前结果

DjS*_*jSh 15

更新:在Vuetify 1.5和2版本中均可使用

要集中v-card-text内容,只需应用class=text-center

v-card-title并且v-card-actions是flex组件,因此通过添加class="justify-center"两者可以集中整个内容:

<v-card-title primary-title class="justify-center">
  <div>
    <h3 class="headline pink--text text--accent-2>Superdry</h3>
    <div>Rookie Aviator Patched BomberproductItem.description</div>
  </div>
</v-card-title>
<v-card-actions class="justify-center">
  <v-btn flat color="orange">Add to Cart</v-btn>
</v-card-actions>
Run Code Online (Sandbox Code Playgroud)

我在您提供的Codepen中使用了您自己的示例。

希望能帮助到你 :)

  • 不客气。实际上你甚至不需要`class =“text-xs-center”`所以我从我的答案中删除了它 (2认同)