Vuetify右侧并排开关。

huangapple go评论59阅读模式
英文:

Vuetify switchers side-by-side on right

问题

I am using vuetify 3 with vuejs 3, and I am trying to create 3 switchers side by side on the right side:

<template>
  <v-card variant="outlined" class="pa-6 ma-3" color="#BDBDBD">
    <v-row class="pa- ma-0">
      <v-btn
        color="primary"
        class="mr-2"
        :loading="loading"
        :disabled="loading"
      >
        Atualizar
      </v-btn>
      <v-btn color="error" :disabled="selected.length == 0" class="mr-2">
        Plotar
      </v-btn>
      <v-btn color="warning" :disabled="selected.length == 0" class="mr-3">
        Favoritar
      </v-btn>
      <v-row class="ml-3 black-label">
        <v-switch
          label="Intraday"
          v-model="intraday"
          color="primary"
          hide-details
        ></v-switch>
        <v-switch
          label="Stocks"
          v-model="stocks"
          color="primary"
          hide-details
        ></v-switch>
        <v-switch
          label="Favorites"
          v-model="favorites"
          color="primary"
          hide-details
        ></v-switch>
      </v-row>
    </v-row>
  </v-card>
</template>

<script setup>
  import { ref } from 'vue'
  const search = ref('')
  const selected = ref([])
  const intraday = ref(false)
  const favorites = ref(false)
  const stocks = ref(false)
  const loading = ref(false)
  const msg = ref('Hello World!')
</script>

Reproducible example

I've tried to change v-switch class to mr-3 as I did with buttons, but I couldn't get the expected output.

英文:

I am using vuetify 3 with vuejs 3, and I am trying to create 3 switchers side by side on the right side:

Vuetify右侧并排开关。

&lt;template&gt;
  &lt;v-card variant=&quot;outlined&quot; class=&quot;pa-6 ma-3&quot; color=&quot;#BDBDBD&quot;&gt;
    &lt;v-row class=&quot;pa- ma-0&quot;&gt;
      &lt;v-btn
        color=&quot;primary&quot;
        class=&quot;mr-2&quot;
        :loading=&quot;loading&quot;
        :disabled=&quot;loading&quot;
      &gt;
        Atualizar
      &lt;/v-btn&gt;
      &lt;v-btn color=&quot;error&quot; :disabled=&quot;selected.length == 0&quot; class=&quot;mr-2&quot;&gt;
        Plotar
      &lt;/v-btn&gt;
      &lt;v-btn color=&quot;warning&quot; :disabled=&quot;selected.length == 0&quot; class=&quot;mr-3&quot;&gt;
        Favoritar
      &lt;/v-btn&gt;
      &lt;v-row class=&quot;ml-3 black-label&quot;&gt;
        &lt;v-switch
          label=&quot;Intraday&quot;
          v-model=&quot;intraday&quot;
          color=&quot;primary&quot;
          hide-details
        &gt;&lt;/v-switch&gt;
        &lt;v-switch
          label=&quot;Stocks&quot;
          v-model=&quot;stocks&quot;
          color=&quot;primary&quot;
          hide-details
        &gt;&lt;/v-switch&gt;
        &lt;v-switch
          label=&quot;Favorites&quot;
          v-model=&quot;favorites&quot;
          color=&quot;primary&quot;
          hide-details
        &gt;&lt;/v-switch&gt;
      &lt;/v-row&gt;
    &lt;/v-row&gt;
  &lt;/v-card&gt;
&lt;/template&gt;

&lt;script setup&gt;
  import { ref } from &#39;vue&#39;
  const search = ref(&#39;&#39;)
  const selected = ref([])
  const intraday = ref(false)
  const favorites = ref(false)
  const stocks = ref(false)
  const loading = ref(false)
  const msg = ref(&#39;Hello World!&#39;)
&lt;/script&gt;

Reproducible example

I've tried to change v-switch class to mr-3 as I did with buttons, but I couldn't get the expected output.

答案1

得分: 1

你可以只删除v-row元素(我认为它们不应该嵌套),并手动创建你的布局:

  <v-card>
    <div class="d-flex flex-wrap justify-space-between align-center">
      <div>
        button declarations...
      </div>
      <div class="d-flex" style="gap: 20px">
        switch declarations...
      </div>
    </div>
  </v-card>
  • d-flex 将容器变成一个 flexbox,所以两个容器并排放置,我们可以使用 flex 对齐。
  • flex-wrap 允许在没有足够空间时将第二个容器放在新的一行。
  • justify-space-between 会在项目之间放置未使用的空间(这是将开关推到右侧的原因)。
  • align-center 会在垂直方向上居中内容。

playground中查看示例。

英文:

You could just remove the v-row elements (I don't think they should be nested anyway), and create your layout manually:

  &lt;v-card&gt;
    &lt;div class=&quot;d-flex flex-wrap justify-space-between align-center&quot;&gt;
      &lt;div&gt;
        button declarations...
      &lt;/div&gt;
      &lt;div class=&quot;d-flex&quot; style=&quot;gap: 20px&quot;&gt;
        switch declarations...
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/v-card&gt;
  • d-flex turns the container into a flexbox, so the two containers sit next to each other and we can use flex alignment.
  • flex-wrap allows the box to put the second container on a new line when there is not enough space.
  • justify-space-between will put unused space between the items (this is what pushes the switches to the right).
  • align-center will center the content vertically.

Here it is in a playground

huangapple
  • 本文由 发表于 2023年7月3日 09:43:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定