英文:
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>
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:
<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>
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:
<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
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论