我正在使用vutify 3和vuejs 3,我试图在右侧并排创建3个切换器:

enter image description here

<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

我试图将v-Switch类更改为mr-3,就像我对按钮所做的那样,但我无法获得预期的输出.

推荐答案

您只需删除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将容器转换为弹性框,因此两个容器紧挨着坐在一起,我们可以使用弹性对齐.
  • 当没有足够的空间时,flex-wrap允许盒子将第二个容器放在新的生产线上.
  • justify-space-between将在两个项目之间放置未使用的空间(这就是将switch 向右推的地方).
  • align-center将使内容垂直居中.

这是一张playground元的

Vue.js相关问答推荐

Vue composition api: 访问