如何使用Vuetify中的断点为不同的屏幕尺寸指定不同的边距

时间:2018-01-07 12:45:13

标签: vuetify.js

问题:

我有一个循环显示指定数量的卡片。

问题在于ma-5中的<v-flex>属性。在xs屏幕尺寸上,此边距太大。我可以为不同的屏幕尺寸指定不同的保证金吗?

代码:

  
   <v-container>
      <v-layout row wrap>
        <v-flex xs12 sm6 md4 ma-5 v-for="card in filteredCards" :key="card.id">
          <v-card flat class="elevation-20 test">
            <v-card-media :src="card.image" height="200px">
            </v-card-media>
            <v-card-title primary-title class="pa-4">
               <div>
                  <h3 class="headline mb-0">{{card.title}}</h3>
                  <div style="min-height:50px;">{{card.description}}</div>
               </div>
            </v-card-title>
          </v-card>
        </v-flex>
      </v-layout>
   </v-container>

尝试:

我尝试在下面添加此代码(从this页面复制)

<v-flex xs12 sm6 md4 v-for="card in filteredCards" :key="card.id"
   :class="{'ma-0': $breakpoint.smAndDown, 'ma-5': $breakpoint.mdAndUp}">

我收到了这些错误:

  • [Vue warn]: Property or method "$breakpoint" is not defined on the instance but referenced during render

  • [Vue warn]: Error in render: "TypeError: Cannot read property 'smAndDown' of undefined"

  • TypeError: Cannot read property 'smAndDown' of undefined

3 个答案:

答案 0 :(得分:32)

$vuetify.breakpoint.smAndDown

注意$vuetify

在你的情况下:

<v-flex 
    v-for="card in filteredCards"
    :key="card.id"
    :class="{'ma-0': $vuetify.breakpoint.smAndDown, 'ma-5': $vuetify.breakpoint.mdAndUp}"
    xs12 sm6 md4  
>

检查docs(断点对象)

答案 1 :(得分:2)

现在有一种更简单的方法:

<v-card 
  v-for="card in filteredCards"
  :key="card.id"
  class="ma-0 ma-md-5"
>
{{card.title}}
</v-card>

这将XS和SM的边距设为0,将MD和以上的边距设为5

答案 2 :(得分:1)

辅助类在给定的断点处应用边距或填充。可以使用以下格式应用这些类:{property} {direction}-{breakpoint}-{size}。