使用placeholder代替标签,它不会浮动,但一旦做出选择它仍然会消失。要进行纠正,您需要覆盖选择槽以继续显示与以前相同的占位符文本。
<v-select
placeholder="Project Category"
>
<template v-slot:selection="{ item, index }">
<div v-if="index == 0">Project Category</div>
</template>
现在唯一的区别是占位符文本的不透明度是 < 1, while the selection text is 1, so you'll see that opacity change when selecting/unselecting a value. To change the placeholder opacity to match the selection opacity you can add this style:
<style scoped>
.v-select :deep(input::placeholder) {
opacity: 1 !important;
}
</style>
或者,如果您希望选择的不透明度与占位符不透明度相匹配...
<style scoped>
.v-select :deep(.v-select__selection) {
opacity: 0.38 !important;
}
</style>